03-04-2026, 09:15 PM
An updated version of the ebook file/folder tool which I shared on here somewhere in the past:
This simple little tool is the world's biggest timesaver for me. It's not the type of thing that most folks get enthused about, but I'm in LOVE with it for the ease with which it helps to simplify my personal life.
I download books constantly from the interweb. Project gutenberg and other such archive sites are absolutely astounding and utterly amazing to me, and it has been conjectured that I perhaps might also download books from torrents and other such things allegedly.
The problem with downloading books from different sources is they all have their own damn way of storing the info in the file names. Ages and ages ago, I settled on a very simple format for my own archives and collection -- "Author First Name + Last Name + Book Series + Series Number + Book Title + Format"
Problem is, a lot of places like to put their crap in a different format than that.
So I wrote this little tool which simple takes "LAST", "FIRST" names and converts them into "FIRST" + " " + "LAST" names. I just used this earlier and it renamed and corrected over 2000 book titles for me in the space of about 2 seconds. It would've taken me DAYS to do each and every friggin one by hand manually!!
Then, to automate the process further, I run this a second time to automatically read those file names, use them to create the proper directory structure and then I move the books into those folders.
"King, Stephen -- Carrie.epub" becomes "Stephen King\Stephen King -- Carrie.epub"
All in the space of about 5 seconds, I renamed 2000 books, put them in their own directories, and then once I gave them a good once over to make certain they looked like they should, I simply merged them into my existing library.
What would have taken me days to do manually, I did in moments with the help of QB64PE and this little automation tool.
I don't know if anyone else would ever find this useful for their own stuff, but I thought I'd share it anyway. It's sure as hell useful for *ME*!!
Code: (Select All)
$Let RENAME = TRUE
$Let MOVEDIR = FALSE
Screen _NewImage(1280, 720, 32)
ReDim As String FileList(0), f ' be certain to reset your file listing to 0 files like this, before calling the recursive version
Dim i As Long
ChDir "Z:\Books Sorting\"
Disk.File.List "", "", 1, FileList() ' get a list of all files in the directory
$If RENAME Then
'this will rename all the files from "LAST, FIRST -- BOOKTITLE" to "FIRST LAST -- BOOKTITLE"
For i = 1 To UBound(FileList)
b$ = FileList(i)
comma = InStr(b$, ",")
dash = InStr(b$, " - ")
If comma <> 0 _AndAlso comma < dash Then
n$ = Left$(b$, dash)
last$ = _Trim$(Left$(n$, comma - 1))
first$ = _Trim$(Mid$(n$, comma + 1))
newname$ = first$ + " " + last$ + Mid$(FileList(i), InStr(FileList(i), " - "))
Print FileList(i), newname$
Name FileList(i) As newname$
End If
Next
$End If
$If MOVEDIR Then
'this will then take the properly named books and put them in their own subfolders
'so all books by Stephen King are now in a folder called Stephen King
For i = 1 To UBound(FileList)
filename$ = FileList(i)
Print filename$; " =>";
If _FileExists(filename$) Then
period = _InStrRev(filename$, ".")
If period Then
file_no_ext$ = Left$(filename$, period - 1)
Else
file_no_ext$ = filename$
End If
Else
Print "File not found. Check paths for error."
_Continue
End If
dash = InStr(file_no_ext$, " -")
If dash Then file_no_ext$ = Left$(file_no_ext$, dash - 1)
If _DirExists(file_no_ext$) = 0 Then MkDir file_no_ext$
Name filename$ As file_no_ext$ + "\" + filename$
Print file_no_ext$ + "\" + filename$
Next
$End If
Sub Disk.File.List (SearchDir As String, Extension As String, Flag As Long, ReturnArray() As String)
'flags are binary bits which represent the following
'Note that a quick value of -1 will set all bits and return everything for us
'1 -- file listing
'2 -- directory listing
'4 -- sorted (directory before file, like windows explorer does) -- implies 1 + 2 both are wanted.
'8 -- return full path info
Dim As Long FileCount, pass
Dim As String Search, File, Slash
ReDim ReturnArray(1000) As String
If SearchDir = "" Then SearchDir = _CWD$: If Extension = "" Then Extension = "*"
If InStr(_OS$, "WIN") Then Slash = "\" Else Slash = "/"
If Right$(SearchDir, 1) <> "/" _AndAlso Right$(SearchDir, 1) <> "\" Then SearchDir = SearchDir + Slash
Search = SearchDir + Extension
If Flag And 4 Then 'sorted so we get directory listings then files
For pass = 1 To 2 'two passes, first to get directory listings then files
File = _Files$(Search)
Do While Len(File)
If File = ".\" _OrElse File = "..\" Then
Else
If ((pass = 1) _AndAlso _DirExists(SearchDir + File)) _OrElse ((pass = 2) _AndAlso _FileExists(SearchDir + File)) Then
FileCount = FileCount + 1
If FileCount > UBound(ReturnArray) Then ReDim _Preserve ReturnArray(FileCount + 1000) As String
If Flag And 8 Then File = SearchDir + File 'we want the full path info
ReturnArray(FileCount) = File
End If
End If
File = _Files$
Loop
Next
Else 'unsorted so files and directories are simply listed in alphabetical order
File = _Files$(Search) 'one single pass where we just grab all the info at once
Do While Len(File)
If File = ".\" _OrElse File = "..\" Then
Else
If ((Flag And 1) _AndAlso _FileExists(SearchDir + File)) _OrElse ((Flag And 2) _AndAlso _DirExists(SearchDir + File)) Then
FileCount = FileCount + 1
If FileCount > UBound(ReturnArray) Then ReDim _Preserve ReturnArray(FileCount + 1000) As String
If Flag And 8 Then File = SearchDir + File 'we want the full path info
ReturnArray(FileCount) = File
End If
End If
File = _Files$
Loop
End If
ReDim _Preserve ReturnArray(FileCount) As String
End Sub
This simple little tool is the world's biggest timesaver for me. It's not the type of thing that most folks get enthused about, but I'm in LOVE with it for the ease with which it helps to simplify my personal life.
I download books constantly from the interweb. Project gutenberg and other such archive sites are absolutely astounding and utterly amazing to me, and it has been conjectured that I perhaps might also download books from torrents and other such things allegedly.
The problem with downloading books from different sources is they all have their own damn way of storing the info in the file names. Ages and ages ago, I settled on a very simple format for my own archives and collection -- "Author First Name + Last Name + Book Series + Series Number + Book Title + Format"
Problem is, a lot of places like to put their crap in a different format than that.
So I wrote this little tool which simple takes "LAST", "FIRST" names and converts them into "FIRST" + " " + "LAST" names. I just used this earlier and it renamed and corrected over 2000 book titles for me in the space of about 2 seconds. It would've taken me DAYS to do each and every friggin one by hand manually!!
Then, to automate the process further, I run this a second time to automatically read those file names, use them to create the proper directory structure and then I move the books into those folders.
"King, Stephen -- Carrie.epub" becomes "Stephen King\Stephen King -- Carrie.epub"
All in the space of about 5 seconds, I renamed 2000 books, put them in their own directories, and then once I gave them a good once over to make certain they looked like they should, I simply merged them into my existing library.
What would have taken me days to do manually, I did in moments with the help of QB64PE and this little automation tool.

I don't know if anyone else would ever find this useful for their own stuff, but I thought I'd share it anyway. It's sure as hell useful for *ME*!!


