Thanks to JHPJHP, i've finally sorted my PortableApps archive collection into subdirectories. For the first time in 3 years:):)
When you use my code below with his SevenZip library, this will enable you to create subdirectories in the directory where your PortableApps archives reside, based on the category name contained in the appinfo.ini inside the portableapps archive being examined. All but 22 files out of the 550 I had were sorted just fine.
No directory recursion here, didn't need it. Might add a text catalogue later for all the info in the appinfo.ini file.
Code: Select all
Global CurrentPath.s = GetCurrentDirectory()
Global TempDirectory.s = CurrentPath() + "Temporary\"
Declare SortPortableApps(SearchDir.s)
;
Procedure SortPortableApps(Directory.s)
DirectoryId.i = ExamineDirectory(#PB_Any, Directory.s, "*.*")
If DirectoryId.i
Repeat
TypeOfFile.i = NextDirectoryEntry(DirectoryId.i)
FileName.s = DirectoryEntryName(DirectoryId.i)
If TypeOfFile.i = 1
FileName.s = DirectoryEntryName(DirectoryId.i)
CurrentFileName.s = Directory.s + FileName.s
If CurrentFileName.s
szCmdLine.s = "e " + Chr(34) + CurrentFileName.s + Chr(34) + " -aoa -o" + TempDirectory.s + " appinfo.ini -r"
; Debug szCmdLine.s
Result.s = RunCMD(szCmdLine + " -hide") ; Standard ZIP
If FindString(Result, "Can not open file as archive") ; Do not change this message!
Result = Run7zCMD(szCmdLine)
EndIf
; Debug Result
If FindString(Result, "Everything is Ok") ; Do not change this message!
; Debug "appinfo.ini found and extracted"
If OpenPreferences(TempDirectory.s + "appinfo.ini") <> 0
PreferenceGroup("Details")
; Debug ReadPreferenceString("Name", "")
; Debug ReadPreferenceString("AppID", "")
; Debug ReadPreferenceString("Publisher", "")
; Debug ReadPreferenceString("Homepage", "")
; Debug ReadPreferenceString("Category", "")
; Debug ReadPreferenceString("Description", "")
CategoryString.s = ReadPreferenceString("Category", "")
ClosePreferences()
If CategoryString.s <> ""
CreateDirectory(Directory.s + CategoryString.s) ; Don't need to wrap this
If FileSize(Directory.s + CategoryString.s) = -2
If RenameFile(CurrentFileName.s, Directory.s + CategoryString.s + "\" + FileName.s)
Debug "File moved: " + Directory.s + CategoryString.s + "\" + FileName.s
Else
Debug "File not moved: " + FileName.s
EndIf
Else
Debug "Directory: " + CategoryString.s + " does not exist"
EndIf
Else
Debug CategoryString.s + " not found in appinfo.ini, cannot move file"
EndIf
Else
Debug "Could not open: " + TempDirectory.s + "appinfo.ini"
EndIf
Else
Debug "Could not extract appinfo.ini from: " + CurrentFileName.s ; If archive is corrupt, CurrentFileName.s is blank
EndIf
Else
; Debug "There is no current filename"
EndIf
;
Else
; Debug "This is not a file"
EndIf
;
Until TypeOfFile.i = 0
;
Else
Debug "Could not list files in the selected directory"
EndIf
EndProcedure
PathToSearch.s = PathRequester("directory to catalogue", "")
If PathToSearch.s <> ""
SortPortableApps(PathToSearch.s)
Else
Debug "Nothing to do: " + PathToSearch.s + " does not exist or job was aborted"
EndIf