Recursive crc and file list maker
Posted: Mon Mar 03, 2003 8:01 am
Code updated for 5.20+
Restored from previous forum. Originally posted by Fangbeast.
I needed to make a recursive list of files and crc's for thos files so I came up with this. It isn't especially fast and it's a memory hog (because it reads whole files in) but hey, it works for me.
Do what you like with it, improve it, beat the heck out of it etc.
We are Dyslexic of Borg, prepare to have your ass laminated!
Restored from previous forum. Originally posted by Fangbeast.
I needed to make a recursive list of files and crc's for thos files so I came up with this. It isn't especially fast and it's a memory hog (because it reads whole files in) but hey, it works for me.
Do what you like with it, improve it, beat the heck out of it etc.
Code: Select all
#Window_cataloguebar = 0
#Gadget_cataloguebar_cataloguebar = 1
#Gadget_cataloguebar_record = 2
#Gadget_cataloguebar_diskfile = 3
Structure crcitems
crc.s
diskfile.s
EndStructure
NewList crclist.crcitems()
NewList dir.s()
;- Popup a bar to show files being added to the database -----------------------------------------
Procedure.l Window_cataloguebar()
If OpenWindow(#Window_cataloguebar,200,136,740,55, "CrC Catalogue Bar",#PB_Window_SystemMenu | #PB_Window_Invisible)
PanelGadget(#Gadget_cataloguebar_cataloguebar,0,0,740,55)
AddGadgetItem(#Gadget_cataloguebar_cataloguebar,-1,"Adding Files")
StringGadget(#Gadget_cataloguebar_record,5,5,80,20,"")
StringGadget(#Gadget_cataloguebar_diskfile,85,5,645,20,"")
CloseGadgetList()
HideWindow(#Window_cataloguebar,0)
ProcedureReturn WindowID(#Window_cataloguebar)
EndIf
EndProcedure
curdir.s = Space(512)
result = GetCurrentDirectory_(Len(curdir), @curdir) ; Get the current directory
;***********************************************************************************************
; Cataloguing files
;***********************************************************************************************
;- Main code for getting files -----------------------------------------------------------------
If Window_cataloguebar()
ClearList(dir.s())
defaultdrive.s = PathRequester("Please select the drive and directory to catalogue", "")
If Right(defaultdrive.s, 1) = "\"
defaultdrive.s = Left(defaultdrive.s, Len(defaultdrive.s) - 1)
EndIf
AddElement(dir())
dir() = defaultdrive.s
idx = 0
Repeat
SelectElement(dir(), idx)
If ExamineDirectory(0, dir(), "*.*")
path.s = dir() + "\"
quit = 0
While NextDirectoryEntry(0)
filename.s = DirectoryEntryName(0)
Select DirectoryEntryType(0)
Case #PB_DirectoryEntry_File
count + 1
diskfile.s = path + filename.s
;-------------------------------------------------------------------------
If ReadFile(0, diskfile.s) ; Get the 32 bit crc if you can read it
length = Lof(0)
buffer = AllocateMemory(length)
ReadData(0, buffer, length)
AddElement(crclist())
crclist()\crc = Hex(CRC32Fingerprint(buffer, length), #PB_Long)
crclist()\diskfile = diskfile
SetGadgetText(#Gadget_cataloguebar_record, Str(count))
SetGadgetText(#Gadget_cataloguebar_diskfile, crclist()\crc + " - " + filename.s)
While WindowEvent() : Wend
CloseFile(0)
FreeMemory(buffer)
EndIf
;--------------------------------------------------------------------------
Case #PB_DirectoryEntry_Directory
filename.s = DirectoryEntryName(0)
If filename.s <> ".." And filename.s <> "."
AddElement(dir())
dir() = path + filename.s
Debug dir()
EndIf
EndSelect
Wend
EndIf
idx + 1
Until idx > ListSize(dir())-1
SetGadgetText(#Gadget_cataloguebar_diskfile, "Writing data to disk")
If CreateFile(0, curdir + "\CRCFileList.txt")
ResetList(crclist())
While NextElement(crclist())
WriteStringN(0, crclist()\crc + "," + crclist()\diskfile)
Wend
CloseFile(0)
EndIf
EndIf
CloseWindow(#Window_cataloguebar)