Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 9th, 2010 | Syntax: AutoIt | Size: 6.20 KB | Hits: 97 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. #singleinstance force
  2. #NoTrayIcon
  3. SetBatchLines,-1
  4. #NoEnv
  5. #Persistent
  6.  
  7. SetWorkingDir %A_ScriptDir%
  8. SplashImage,, W258 B2 ,,Renaming...
  9. ;_________________________________________________________________________________________________
  10. Clipboard := ""
  11. send ^c
  12. if(clipboard = "")
  13. fileAppend ,
  14.         (
  15.          `n;NothingToAdd=
  16.         ), Renamer.ahk
  17.  
  18.  
  19. fileAppend ,
  20.         (
  21.          `n;%clipboard%=
  22.         ), Renamer.ahk
  23. ;_________________________________________________________________________________________________
  24. Strip( _String )
  25. {
  26.     StringReplace, _String, _String, `r`n, , All
  27.     StringReplace, _String, _String, `r, , All
  28.     StringReplace, _String, _String, `n, , All
  29.     _String = %_String%
  30.     Return, _String
  31. }
  32. /*
  33. indexer( _String, address )
  34. {
  35.         loop, %address%\*,1,0
  36.         {
  37.                 if( _String == A_LoopFileName )
  38.                 {
  39.                         Loop, %address%\*,1
  40.                         {
  41.                                 If InStr(LoopFileName, %_String% . "(1)")
  42.                                         MsgBox hallo
  43.                         }
  44.                 }
  45.         }
  46.         return, _String
  47. }
  48. */
  49.  
  50. listReplace( _String )
  51. {
  52.         start := 0
  53.         loop read, %A_WorkingDir%\Renamer.ahk
  54.         {
  55.                 if ( start = 0 )
  56.                 {
  57.                         if ( A_LoopReadLine = ";!start" )
  58.                         {
  59.                                 start := 1
  60.                         }
  61.                         else
  62.                         {
  63.                                 continue
  64.                         }
  65.                 }
  66.                 else
  67.                 {
  68.                         StringTrimLeft toReplace, A_LoopReadLine, 1
  69.                         StringSplit, replace, toReplace, =
  70.                         StringReplace, _String, _String, %replace1%, %replace2%, ALL
  71.                 }
  72.                 {
  73.                 ; get rid of repeated spaces
  74.                 _String := RegExReplace(_String," +"," ")
  75.                 ; trim whitespace
  76.                 _String = %_String%
  77.                 }
  78.         }
  79.         return _String
  80. }
  81.  
  82.  
  83. ;_string is the file or foldername that needs to be renamed.
  84. ;_flag is to tell the function to work with an extension or not.
  85. ;_flag =  1 will return with extension( for files ).
  86. ;_flag != 1 will return without extension( for folders ).
  87. Replace( _String, _flag )
  88. {
  89.         ;split the extension and filename and put them in seperate strings.
  90.         if _flag = 0
  91.         {
  92.                 splitpath _String,,,_Extension, _String
  93.         }
  94. ;---------------------------------------------------------------------- Replace the following with spaces
  95.         _String := RegExReplace(_String,"\.|_|-"," ")
  96. ;---------------------------------------------------------------------- Replace the following with blanks
  97.         _String := RegExReplace(_String,"\/|\\|\(|\)|\@|\!|\[|\]|\;|\+|\=|#|\$|\%|\^|\&","")
  98. ;---------------------------------------------------------------------- Title case options
  99. ;---------------------------------------------------------------------- Title case every word
  100.         _String := RegExReplace(_String,".*","$T0")
  101. ;---------------------------------------------------------------------- Title case the first letter only
  102. ;       {
  103. ;               StringLower, _String, _String
  104. ;               FirstChar:=SubStr(_String, 1, 1)
  105. ;               StringUpper, FirstChar, FirstChar
  106. ;               _String:=SubStr(_String, 2)
  107. ;               _String:=FirstChar _String
  108. ;       }
  109. ;---------------------------------------------------------------------- Replacment
  110.         _String := listReplace( _String )
  111.  
  112. ;---------------------------------------------------------------------- Replaces spaces among numbers with dots
  113.                 _String:=RegExReplace(_String, "((\d+)\s+(?=\d))", "$2.")
  114. ;---------------------------------------------------------------------- Title case words after -
  115.                 _String:=regexreplace(_String,"(-|- )(\w)","$1$T2")
  116.  
  117.         ;put the filename + extension in a string to check if theres a space before the ext.
  118.         output := _String . "." . _extension
  119.         ext_space := " ."
  120.         extreplace := "."
  121.         StringReplace output, output, %ext_space%, %extreplace%, ALL
  122.        
  123.         ;return with extension if _flag is 0, for files.
  124.         if _flag = 0
  125.                 return, output
  126.         ;return the new string when _flag != 0, for folders.
  127.         else
  128.                 return, _string
  129. }
  130. rename(address)
  131. {
  132.  
  133.         ;rename all files in open explorer window.
  134.         loop, %address%\*
  135.         {
  136.                 output := Replace(A_LoopFileName, 0)                            ;output becomes the new filename.
  137.                 path_to := A_LoopFileDir . "\" . output                         ;new dir + file name.
  138.                 path_from := A_LoopFileDir . "\" . A_LoopFileName       ;old dir + file name.
  139.                 filemove %path_from%, %path_to%                                         ;rename the current file.
  140.         }
  141.         ;rename all folders in open explorer window
  142.         loop, %address%\*,2,2
  143.         {              
  144.                 output := Replace(A_LoopFileName, 1)                            ;output becomes the new foldername.
  145.                 path_to := A_LoopFileDir . "\" . output                         ;new dir + folder name.
  146.                 path_from := A_LoopFileDir . "\" . A_LoopFileName       ;old dir + folder name.
  147.                 filemovedir %path_from%, %path_to%                                      ;rename the current folder.
  148.                 rename(path_to)
  149.         }
  150. }
  151.  
  152. ;---------------------------------------------------------------------- Execute Renamer
  153. ifwinexist, ahk_class CabinetWClass
  154. {
  155.         ;get the path from an existing windows explorer window
  156.         ;and remove the "address:" line from it.
  157.         ControlGetText, OutputVar, toolbarwindow322, ahk_class CabinetWClass
  158.         stringreplace, address, OutputVar, Address:
  159.         ;strip the invisible newline etc characters.
  160.         address := Strip( address )
  161.         rename(address)
  162. }
  163. ;_________________________________________________________________________________________________
  164. FileRead, filevar, Renamer.ahk
  165. StringGetPos, lastline, filevar, `r`n, R
  166. TrimMe := strlen(filevar) - lastline
  167. StringTrimRight, filevar, filevar, %TrimMe%
  168. FileDelete, Renamer.ahk
  169. FileAppend, %filevar%, Renamer.ahk
  170. ;_________________________________________________________________________________________________
  171. SplashImage off
  172. ExitApp
  173.  
  174. ;---------------------------------------------------------------------- Replacment list
  175. ;!start
  176. ;1080I=
  177. ;Orenji=
  178. ;With Jon Stewart=
  179. ;Iplayer=
  180. ;Aac Dokus4alle=
  181. ;H264=
  182. ;The The=The
  183. ;bbc=BBC
  184. ;Www Mvgroup Org=
  185. ;Mvgroup Org=
  186. ;En De Fr=
  187. ;Xvid Ac3=
  188. ;Pdtv=
  189. ;Xvid Mp3=
  190. ;X264=
  191. ;Multi Audio=
  192. ;Ac3=
  193. ;Divx=
  194. ;Xvid=
  195. ;Ws Ekolb=
  196. ;Aac=
  197. ;Dvb=
  198. ;[Desibbrg Com]=
  199. ;Discovery=Discovery Channel
  200. ;Channel Channel=Channel
  201. ;Channel Channel=
  202. ;Channel - Channel=Channel
  203. ;Mvgroup Forum=
  204. ;Docs4you=
  205. ;Ch4=Channel 4 -
  206. ;Momentum=
  207. ;Mpeg2=
  208. ;Dd2=
  209. ;0 Ctrl=
  210. ;ws ftp=
  211. ;hitler=Hitler
  212. ;pill poppers=Pill Poppers
  213. ;BBC - BBC Horizon=BBC Horizon
  214. ;3 511=3
  215. ;omicron=
  216. ;xivd=
  217. ;Kere wsilluminatenboard org=
  218. ;!F9::=
  219. ;!F9::=
  220. ;xitApp=
  221. ;SetWorkingDir %A_ScriptDir%=
  222. ;mvgroup=
  223. ; ws=
  224. ;dts wiki=
  225. ;-.=-
  226. ;dvdr=
  227. ;Nl=NL
  228. ;Sp2=SP2
  229. ;Mi2=
  230. ;Richard Dawkins=Richard Dawkins -
  231. ;hdtdi=How Do They Do It -
  232. ;,= -
  233. ;Dd5 1=
  234. ;Ctrl=
  235. ;tv=
  236. ;Pbs=PBS
  237. ;Ftp=
  238. ;Dvsky=
  239. ;Readnfo=
  240. ; Hd=
  241. ;1180=Sahin
  242. ;x264=
  243. ;HDTV=
  244. ;264=
  245. ;BBC Horizon=BBC Horizon -
  246. ;Sfm=