The file names are something like this:
Book Title (1) (epub),epub
Book Title (2) (azw3),azw3
Book Title (4) (retail) (azw3),azw3
The purpose of the program is to rename the files minus the bracketed (epub), (azw3),(retail) (azw3), etc.
So far everything works perfectly, except that it does not return the string position of (retail) when using FindString.
Code: Select all
Global NewList Directories.s()
Global NewList Name.s()
Global NewList ExtnList.s() ; The actual list is longer than shown here
AddElement(ExtnList())
ExtnList() = " (retail)" ; <- This is the missed lement.
AddElement(ExtnList())
ExtnList() = " (epub)"
AddElement(ExtnList())
ExtnList() = " (azw3)"
AddElement(ExtnList())
ExtnList() = " (mobi)"
AddElement(ExtnList())
ExtnList() = " (html)"
AddElement(ExtnList())
ExtnList() = " (pdf)"
; Possible that not all the following varibals will be used in final code
Temp.s
Fpath.s = "E:\Test\Books\"
FileNew.s
FileOld.s
Fextn.i
Counter.i = 0
FpLen.i = Len(Fpath)
ExtLen.i
Procedure ListFilesRecursive(Dir.s, List Files.s())
; Procedure code thanks to Trond https://tinyurl.com/26774zez
If Right(Dir, 1) <> "\"
Dir + "\"
EndIf
D = ExamineDirectory(#PB_Any, Dir, "")
While NextDirectoryEntry(D)
Select DirectoryEntryType(D)
Case #PB_DirectoryEntry_File
AddElement(Files())
Files() = Dir + DirectoryEntryName(D)
Case #PB_DirectoryEntry_Directory
Select DirectoryEntryName(D)
Case ".", ".."
Continue
Default
AddElement(Directories())
Directories() = Dir + DirectoryEntryName(D)
EndSelect
EndSelect
Wend
FinishDirectory(D)
ForEach Directories()
ListFilesRecursive(Directories(), Files())
Next
EndProcedure
ListFilesRecursive(Fpath, Name())
ForEach Name()
Counter + 1
ForEach ExtnList()
Temp = Right(Name(), Len(Name()) - FpLen)
; Problem with the following
x = FindString(Temp, ExtnList()) ; This works for everything except the first list element.
If x > 0
FileNew = Left(Temp, x - 1) + "*"
Debug FileNew
EndIf
Next
; File rename will go here
Next
Debug "File Count = " + Str(Counter)
FreeList(Directories())
FreeList(Name())
FreeList (ExtnList())
Jay