Advertisement
Linda-chan

UpdateDescriptIonFile.VBS

Dec 13th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Const AppPath = "AJPapps - Update Descript.ion file"
  4.  
  5. Const URL_PREFIX_DB = "http://dl.dropboxusercontent.com/u/!!!!!!!/"
  6.  
  7. Const vbNormal = 0
  8. Const vbReadOnly = 1
  9. Const vbHidden = 2
  10. Const vbSystem = 4
  11. Const vbVolume = 8
  12. Const vbDirectory = 16
  13. Const vbArchive = 32
  14. Const vbAlias = 64
  15. Const vbCompressed = 128
  16.  
  17. Dim FSO
  18. Dim Folder
  19. Dim File
  20. Dim LinksText
  21. Dim TXT
  22. Dim Stream
  23. Dim PathPrefix
  24.  
  25. Set FSO = CreateObject("Scripting.FileSystemObject")
  26. Set Folder = FSO.GetFolder(".")
  27.  
  28. For Each File In Folder.Files
  29.   If Not IsExcludedFile(File.Name) Then
  30.     StripPathPrefix File.Path, TXT
  31.     If TXT = "" Then
  32.       WScript.Echo "Can't strip Dropbox path."
  33.       WScript.Echo "Press Enter to continue..."
  34.       WScript.Stdin.ReadLine
  35.       WScript.Quit
  36.     End If
  37.    
  38.     TXT = Replace(TXT, "\", "/")
  39.     TXT = Replace(TXT, "%", "%25")
  40.     TXT = Replace(TXT, "#", "%23")
  41.     TXT = Replace(TXT, " ", "%20")
  42.  
  43.     TXT = Replace(TXT, "(", "%28")
  44.     TXT = Replace(TXT, ")", "%29")
  45.     TXT = Replace(TXT, "[", "%5B")
  46.     TXT = Replace(TXT, "]", "%5D")
  47.    
  48.     TXT = URL_PREFIX_DB & TXT
  49.    
  50.     LinksText = LinksText & """" & File.Name & """   " & TXT & vbCrLf
  51.   End If
  52. Next
  53.  
  54. On Error Resume Next
  55.  
  56. If FSO.FileExists("Descript.ion") Then
  57.   FSO.GetFile("Descript.ion").Attributes = vbNormal
  58.  
  59.   If Err.Number <> 0 Then
  60.     WScript.Echo "Can't set attributes for Descript.ion file."
  61.     WScript.Echo "Press Enter to continue..."
  62.     WScript.Stdin.ReadLine
  63.     WScript.Quit
  64.   End If
  65. End If
  66.  
  67. Set Stream = FSO.CreateTextFile("Descript.ion", True, False)
  68. Stream.Write CharToOem(LinksText)
  69. Stream.Close
  70.  
  71. If Err.Number <> 0 Then
  72.   WScript.Echo "Can't write Descript.ion file."
  73.   WScript.Echo "Press Enter to continue..."
  74.   WScript.Stdin.ReadLine
  75.   WScript.Quit
  76. End If
  77.  
  78. FSO.GetFile("Descript.ion").Attributes = vbHidden Or vbArchive
  79.  
  80. If Err.Number <> 0 Then
  81.   MsgBox Err.Description
  82.   WScript.Echo "Can't set attributes for Descript.ion file."
  83.   WScript.Echo "Press Enter to continue..."
  84.   WScript.Stdin.ReadLine
  85.   WScript.Quit
  86. End If
  87.  
  88. '====================================================================
  89. Private Sub StripPathPrefix(ByVal FileName, _
  90.                             ByRef PathText)
  91.   Dim RC
  92.  
  93.   Const SEARCH_STR_1 = "\DROPBOX\PUBLIC\"
  94.   Const SEARCH_STR_2 = "\MY DROPBOX\PUBLIC\"
  95.  
  96.   RC = Instr(UCase(FileName), SEARCH_STR_1)
  97.   If RC > 0 Then
  98.     PathText = Mid(FileName, RC + Len(SEARCH_STR_1))
  99.     Exit Sub
  100.   End If
  101.  
  102.   RC = Instr(UCase(FileName), SEARCH_STR_2)
  103.   If RC > 0 Then
  104.     PathText = Mid(FileName, RC + Len(SEARCH_STR_2))
  105.     Exit Sub
  106.   End If
  107.  
  108.   PathText = ""
  109. End Sub
  110.  
  111. '====================================================================
  112. Private Function IsExcludedFile(ByVal FileName)
  113.   Select Case UCase(FileName)
  114.     Case "DESCRIPT.ION"
  115.       IsExcludedFile = True
  116.     Case Else
  117.       IsExcludedFile = False
  118.   End Select
  119. End Function
  120.  
  121. '====================================================================
  122. ' Перекодировка с использованием встроенного объекта.
  123. ' Найдено тут: http://forum.script-coding.com/viewtopic.php?id=1179
  124. '====================================================================
  125. Private Function CharToOem(ByVal Text)
  126.   CharToOem = CharTranslate(Text, "windows-1251", "cp866")
  127. End Function
  128.  
  129. Private Function OemToChar(ByVal Text)
  130.   OemToChar = CharTranslate(Text, "cp866", "windows-1251")
  131. End Function
  132.  
  133. Private Function CharToUtf8(ByVal Text)
  134.   CharToUtf8 = CharTranslate(Text, "windows-1251", "utf-8")
  135. End Function
  136.  
  137. Private Function Utf8ToChar(ByVal Text)
  138.   Utf8ToChar = CharTranslate(Text, "utf-8", "windows-1251")
  139. End Function
  140.  
  141. '====================================================================
  142. ' Общая функция перекодировки из чего угодно во что угодно.
  143. '====================================================================
  144. Function CharTranslate(ByVal Text, _
  145.                        ByVal SourceCharset, _
  146.                        ByVal DestCharset)
  147.   Dim Stream
  148.  
  149.   Set Stream = CreateObject("ADODB.Stream")
  150.   Stream.Type = 2
  151.   Stream.Mode = 3
  152.   Stream.Open
  153.   Stream.Charset = DestCharset
  154.   Stream.WriteText Text
  155.   Stream.Position = 0
  156.   Stream.Charset = SourceCharset
  157.   CharTranslate = Stream.ReadText
  158. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement