topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday February 27, 2021, 3:51 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Andreasvb [ switch to compact view ]

Pages: [1]
1
N.A.N.Y. 2010 / Re: pyrohacker
« on: July 17, 2016, 04:52 AM »
Hi, I got a slightly modded version of your code.

I used this before and thought I would sort my download-folder now, but it didn't work today (Windows 10).
Thought I would see if there was an update for it, and read that you lost it.

Also, I wanted only the year, so I put together a little bat script instead. :)

Used some bits from these 2 to get it working so it will not move any .bat:
http://stackoverflow.com/a/22222204 [Batch file to move file based on Month & Year on Date modified to folder with YYYY_MM]
http://stackoverflow.com/a/863627 [In a batch file, how do I delete all files NOT of a certain type]

Code: Visual Basic [Select]
  1. @echo off
  2. cls
  3. choice /c yn /t 10 /d n /m "move all files divided by year?"
  4. if errorlevel 2 goto stop
  5. for %%f in ("%cd%\*") do if not %%~xf==.bat (
  6.   for /f "tokens=1 delims=- " %%a in ("%%~tf") do (
  7.     if not exist "%cd%\%%a" mkdir "%cd%\%%a"
  8.     move "%%~f" "%cd%\%%a"
  9.   )
  10. )
  11. cls
  12. echo all done!
  13. timeout 10
  14. :stop
  15. exit



Here's the code for your script (modded for YYYY-MM)
Code: Autohotkey [Select]
  1. /*
  2. SubDiv
  3. created by pyrohacker on the D.C. Forum
  4. as a NANY 2010 Entry.
  5. */
  6.  
  7. SetWorkingDir %A_ScriptDir%
  8. Menu, TRAY, Icon,,, 1
  9.  
  10. ; Set up GUIs and variables
  11.  
  12. Setup:
  13.  
  14.  
  15. Separator=%SeparatorSelection%
  16. Cleanup=%CleanupSetAt%
  17.  
  18. FormatTime, CurrentYear,, yyyy
  19. FormatTime, CurrentMonth,, MM
  20. FormatTime, CurrentDay,, dd
  21.  
  22. ; Create the settings dialog
  23. Gui, 3:Add, Text,, Creates folders: Year && Months`n:: Andreasvb 2012 mod ::
  24. FormatTime, SmartDate,, yyyy - M - d
  25. Gui, 3:Add, Text,, Please select a date separator:
  26. Gui, 3:Add, Radio, Checked%UnderscoreOn% vSeparatorSelection, Underscore ( _ )
  27. Gui, 3:Add, Radio, Checked%HyphenOn% y+0, Hyphen ( - )
  28. Gui, 3:Add, Radio, y+15 Group Checked, Update Mode
  29. Gui, 3:Add, Radio, y+0 Disabled, Monitor Mode
  30. Gui, 3:Add, Checkbox, y+10 %Recursive% vRecurseSetAt, Recursive subfolders
  31. Gui, 3:Add, Checkbox, y+5 %Cleanup% vCleanupSetAt, Delete empty folders
  32. Gui, 3:Add, Button, y+20 x20 w70 gSendSettings, Apply
  33. Gui, 3:Add, Button, x+15 w70 gActions, Cancel
  34.  
  35. Start:
  36.  
  37. ; Create the Main Actions Dialog
  38. Gui, 2:Add, Button, vUpdate gSortNow h120 w120, Sort this folder now
  39. Gui, 2:Add, Button, vSettings gShowSettings x+0 h120 w120, Change settings
  40. Gui, 2:+ToolWindow
  41. Gui, 2:Show, Center, SubDiv
  42. Pause On
  43.  
  44. Actions:
  45. Pause Off
  46. Gui, 3:Hide
  47. Gui, 2:Show, Center, SubDiv
  48. Pause On
  49.  
  50. SortNow:
  51. Pause Off
  52. Loop %A_WorkingDir%\*, 0, %Recursive% ; Retrieve a list of files to be sorted
  53.         NewFiles = %NewFiles%%A_LoopFileName%`n
  54. UpdateFolders()
  55. StringTrimRight, SortTime, %A_Now%, 6
  56. if Separator = 1
  57.         UnderscoreSort()
  58. if Separator = 2
  59.         HyphenSort()
  60. if ErrorLevel = 0
  61.         GoSub Problems
  62. MsgBox Finished sorting %A_WorkingDir%!
  63. GoSub EndProg
  64.  
  65. UpdateFolders()
  66. {
  67. global
  68.  
  69. If (Cleanup == 1) {
  70.  
  71. Loop, *, 2,
  72. {
  73.   Size = 0
  74.   Loop, %A_LoopFileName%\*, 1, 1
  75.   {
  76.     Size += %A_LoopFileSize%
  77. }
  78. ;MsgBox Size of %A_LoopFileName% is %A_LoopFileSize% bytes.
  79. If (Size < 1) {
  80. FileRecycle, %A_LoopFileName%
  81. }
  82.  
  83. }
  84.  
  85.  
  86. }
  87. Return
  88. }
  89.  
  90. HyphenSort()
  91. {
  92. global
  93. Loop PARSE, NewFiles, `n
  94. {
  95.         FileGetTime DateCreated, %A_LoopField%, C
  96.         FormatTime, YearCreated, %DateCreated%, yyyy
  97.         NowTime := SortTime
  98.         EnvSub, NowTime, %DateCreated%, Days
  99.         IfInString, A_LoopField, SubDiv
  100.                 Continue
  101.        
  102.                 FormatTime, FolderName, %DateCreated%, yyyy
  103.        
  104.        
  105.         FileCreateDir %FolderName%
  106.         FileMove %A_LoopField%, %FolderName%
  107.         EverRun=1
  108. }
  109. Return
  110. }
  111.  
  112. UnderscoreSort()
  113. {
  114.         global
  115.         Loop PARSE, NewFiles, `n
  116.         {
  117.                 FileGetTime DateCreated, %A_LoopField%, C
  118.                 FormatTime, YearCreated, %DateCreated%, yyyy
  119.                 NowTime := SortTime
  120.                 EnvSub, NowTime, %DateCreated%, Days
  121.                 IfInString, A_LoopField, SubDiv
  122.                         Continue
  123.                
  124.                         FormatTime, FolderName, %DateCreated%, yyyy
  125.                
  126.                
  127.                 FileCreateDir %FolderName%
  128.                 FileMove %A_LoopField%, %FolderName%
  129.                 EverRun=1
  130.         }
  131.         Return
  132. }
  133.  
  134.  
  135. ShowSettings:
  136. Pause Off
  137. Gui, 3:Show, Center, Settings Dialog:
  138. Pause On
  139.  
  140. SendSettings:
  141.  
  142. Separator=%SeparatorSelection%
  143. Cleanup=%CleanupSetAt%
  144.  
  145.  
  146. if (RecurseSetAt = 1) and (RecurseWarning = 0)
  147. {
  148.         MsgBox, 4, Caution:, You have instructed SubDiv to sort all files in this folder, including files inside subfolders.`nDoing this will destroy the folder structures in the sorted directory.  Are you sure?
  149. RecurseWarning=1
  150.         IfMsgBox No
  151.                 GoSub ShowSettings
  152. }
  153.  
  154.  
  155. Recursive=%RecurseSetAt%
  156.  
  157. Gui, 3:Hide
  158. Gosub Start
  159.  
  160. Problems:
  161. MsgBox Unknown problems were encountered, but I can't say what...
  162.  
  163. 3GuiClose:
  164. return
  165. EndProg:
  166. 2GuiClose:

Pages: [1]