Page 1 of 1

File sorter

Posted: Sat Nov 28, 2009 12:57 am
by jamirokwai
Hiya,

today I had the problem of thousands of files in one directory. The files should be moved into a folder with a single letter from A - Z, 0 (zero) and a-z. Finally I used a part of the example for ExamineDirectory() to do this task... This snippet will create 26 folders from A to Z. You have to create a 0 (Zero)-folder manually and move the missing files there... Just choose the right directory to start from. This sorts 20.000 or so files in under 10 Seconds on my MacBook Pro...
Hope, someone finds this useful.

Code: Select all

tmp$ = PathRequester("search path", GetCurrentDirectory())
SetCurrentDirectory(tmp$)
;For i = 65 To 90 ; (A = 65, Z = 90)  ; change here to A - Z or a - z
For i = 97 To 122 ; a-z ; was to lazy to do this in a single FOR-loop...
If ExamineDirectory(0,tmp$, Chr(i) + "*.*")
 CreateDirectory(tmp$ + Chr(i))
 While NextDirectoryEntry(0)
  If DirectoryEntryType(0) = #PB_DirectoryEntry_File
   Name$ = DirectoryEntryName(0)
   RenameFile(tmp$ + Name$, tmp$ + Chr(i) + "/" + Name$)
  EndIf
 Wend
 FinishDirectory(0)
EndIf
Debug Chr(i) 
Next i