2
0

Move Image Files.ahk 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * -- Move Image Files using 'Image Files List.txt'--
  3. *
  4. * Requires images subfolder to exist in current directory
  5. *
  6. * ImageFileList - List of file names from glife.txt and Auto List
  7. * UsedImageFolder - Folder to move images in ImageFileList
  8. * UnUsedImageFolder - Folder to move images not in ImageFileList
  9. * SourceFolder - Folder with images
  10. *
  11. *
  12. * WD: Jul 2015
  13. *
  14. *
  15. */
  16. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  17. #Warn ; Enable warnings to assist with detecting common errors.
  18. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  19. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  20. ImageFileList = Image List - Used.txt
  21. UsedImageFolder = Images, Used
  22. UnUsedImageFolder = Images, Un-Used
  23. SourceFolder = images
  24. FileEncoding, UTF-16
  25. ;-- backup files and delete --
  26. IfNotExist %ImageFileList%
  27. {
  28. MsgBox, 16, Move Image Files, Unable to locate "%ImageFileList%" in "%A_WorkingDir%", 10
  29. Exit
  30. }
  31. IfNotExist %UsedImageFolder%
  32. {
  33. FileCreateDir, %UsedImageFolder%
  34. }
  35. IfNotExist %UnUsedImageFolder%
  36. {
  37. FileCreateDir, %UnUsedImageFolder%
  38. }
  39. ; -- load data from file --
  40. FileRead, Images, %ImageFileList%
  41. Images := StrReplace(Images, "/", "\") ;; Use correct Win path seperator
  42. ; -- Parse data one line at a time --
  43. Loop, Parse, Images, `n, `r ; Specifying `n prior to `r allows both Windows and Unix files to be parsed.
  44. {
  45. if trim(A_LoopField) = "" ;; Skip blank line
  46. continue
  47. IfExist, %A_LoopField%
  48. {
  49. ; -- Create Dir if id dosn't exist --
  50. SplitPath, A_LoopField, FileName, FileDir
  51. IfNotExist %UsedImageFolder%\%FileDir%
  52. {
  53. FileCreateDir, %UsedImageFolder%\%FileDir%
  54. if (ErrorLevel)
  55. {
  56. MsgBox, 48, Move Image File, FileCreateDir Error:`n`nFailed to create '%UsedImageFolder%\%FileDir%'`n`nErrorLevel: '%ErrorLevel%'`nLastError: '%A_LastError%'
  57. }
  58. }
  59. ; -- move file --
  60. FileMove, %A_LoopField%, %UsedImageFolder%\%FileDir%
  61. if (ErrorLevel)
  62. {
  63. MsgBox, 48, Move Image File, FileMove Error:`n`nFailed to move '%A_LoopField%' to '%UsedImageFolder%\%FileDir%'`n`nErrorLevel: '%ErrorLevel%'`nLastError: '%A_LastError%'
  64. }
  65. }
  66. else ; -- File dosn't exist --
  67. {
  68. MsgBox, 64, Move Image Files, Unable to locate file : '%A_LoopField%', 5
  69. }
  70. }
  71. ; -- Rename Images folder to unused Images folder --
  72. IfExist %SourceFolder%
  73. {
  74. FileMoveDir, %SourceFolder%, %UnUsedImageFolder%\%SourceFolder%
  75. if (ErrorLevel)
  76. {
  77. MsgBox, 48, Move Image File, FileMoveDir Error:`n`nFailed to move '%SourceFolder%' to '%UnUsedImageFolder%\%SourceFolder%'`n`nErrorLevel: '%ErrorLevel%'`nLastError: '%A_LastError%'
  78. }
  79. ; -- Rename Used Images folder to Images folder --
  80. else IfNotExist %SourceFolder%
  81. {
  82. FileMoveDir, %UsedImageFolder%\%SourceFolder%, %SourceFolder%
  83. if (ErrorLevel)
  84. {
  85. MsgBox, 48, Move Image File, FileMoveDir Error:`n`nFailed to move '%UsedImageFolder%\%SourceFolder%' to '%SourceFolder%'`n`nErrorLevel: '%ErrorLevel%'`nLastError: '%A_LastError%'
  86. }
  87. else
  88. {
  89. FileRemoveDir, %UsedImageFolder%, 0 ;; Delete Empty Folder
  90. }
  91. }
  92. }