Stab In The Dark
This is the code that scan our intended directory. It's basically about the same as BatVink code above.
The code is divided into 3 parts:
1st - Declare all required arrays and variables at the program start
2nd - Scan the first layer of the files and folders in the specified directory, at the program start
3rd- This part is in the main loop. This part will detect which folder is not explored yet in our array, and scan the next layer of folders and files. Each loop, a new/deeper layer of files will be explored.
This example scans the D drive. Change this line in the 1st part of the code:
GLOBAL baseDir$ = "D:\"
to whatever directory you want it to scan.
*some of the variables and part of the array, such as prevDir$, leftclick, is redundant and not used, or used in the algorithm to create the file city, which is not related to our problem, sooooo
1st part
Function DefineSearchVar()
`global baseDir$ = "D:"
`baseDir$ = "D:\Gamecube roms"
GLOBAL HostDirectory$
`SetFolder("")
HostDirectory$ = GetFolder()
GLOBAL baseDir$ = "D:"
`baseDir$ = "D:\Music"
`set dir baseDir$
//Set intended directory
SetRawWritePath(baseDir$)
SetFolder("")
`Global baseDir$
`baseDir$ = GetWritePath()
`GLOBAL prevDir$
`prevDir$ = GetWritePath()
global leftclicked = 0
global firstfile = 0
global filesearch = 0
global fileLevel = 0
global currentfile$
global currentFileType = 0
global prevDir$
prevDir$ = baseDir$
global prevDirArray = 1
global tempPrevDir$ as string
tempPrevDir$ = baseDir$
`global baseDir$
`baseDir$ = baseDir$
`global boxsize# as double float
`global fileSize as double integer
global boxsize# as float
global fileSize as integer
global allowMakeBox = 0
global cityMade = 0
global cityFinished = 0
global lastArray = 0
global boxmade = 0
global fileMade = 0
global fileNotMade = 0
global fileNotExplored = 0
global FolderSizeCalculated = 0
`global folderSize as double integer `temporary variable to store folder size/height
global folderSize as integer `temporary variable to store folder size/height
global limbCollisionNum = 0 `the number of limb made for collision purpose. Also the number of object (limbCollisionNum + terrainNum)
GLOBAL currentFileObjNum = 0 `current object number use for making boxes for files
global currentlyStandingOnFolder = 0
global previouslyStandingOnFolder = 0
global temporaryBuildingGeneration = 0 `mark if files inside the folder player is standing on has finished being made
global folderChange = 0 `mark if folder that player is standing on is changing
global ArrayScanLimit
global ArrayScanStart
global ArrayScanLimitDetected = 0
global ArrayScanStartDetected = 0
global initialFileLimit = 500
global maxFileLimit = 999
global ArraySaved = 0
`global NPCcontrol : ` 0 = auto , 1 = manual
`Global main terrain objects
global terrainNum = 10
global lastObj = 10
currentFileObjNum = lastObj
global dim FileName$[2000000,3] as string
`LOAD ARRAY "FileName",FileName$(0,0)
`FileName$(1,1) = "filename" `file name
`FileName$(1,2) = "fileDir" `the directory that this file is in
`FileName$(1,3) = baseDir$ `the directory that the parent folder of this file is in
global dim FileNum[2000000,10] as integer
`LOAD ARRAY "FileNum",FileNum(0,0)
`FileNum(1,1) = objNum `number of object representing this file
`FileNum(1,2) = fileLevel
`FileNum(1,3) = fileSize
`FileNum(1,4) = boxmade `boxmade = 1 if box reperesenting this file was made
`FileNum(1,5) = indexed
`FileNum(1,6) = explored
`FileNum(1,7) = fileType
`FileNum(1,8) = PrevFolderArrayNumber
`FileNum(1,9) = fileObjNum `obj number for obj created for this object
global dim currentVariables[5]
`LOAD ARRAY "currentVariables",currentVariables(0)
currentVariables[1] = fileNotMade
currentVariables[2] = lastObj
REM store created objects data, such as the number of file it refers to in FileNum(2000000,10) array. Used to store temporarily created object reference data
global dim objectReference[200000,5]
`objectReference[1,1] = arrayNum
REM Create strings for file names display
FOR b = 1 TO 1000
CreateText ( b, "" )
SetTextSize( b, 20 )
NEXT b
fileSearch = 1
2nd part
Function SearchDriveInitialize()
`perform checklist for files `Check files current directory
itemCount = GetFileCOunt() + GetFolderCount()
`====================================================================================================================================================================
`Register FILES info in base directory
If GetFileCOunt() > 0
`FOR t = (1) to GetFileCOunt()
FOR t = (1) to GetFileCOunt()
`Register first file info
If (t = 1)
`GetFirstFile()
currentfile$ = GetFirstFile()
print( currentfile$ )
currentpath$ = GetWritePath()
iFileID = OpenToRead(currentfile$)
`pathExist = path exist(baseDir$+"/"+currentfile$)
fileSize = 0
fileSize = GetFileSize(iFileID)
`If current folder is . or .. , skip and open other folder
IF (currentfile$ = "Test File City.agk") or (currentfile$ = "Test File City.exe") or (currentfile$ = "System Volume Information") or (currentfile$ = "main.agc") or (currentfile$ = "FileSearch.agc") or (currentfile$ = "steam_api.dll") or (currentfile$ = "steam_appid.txt")
`Don't do anything
ELSE `if other name, allow set directory
`Register this file info in array
lastobj = lastobj + 1
FileNum[lastobj,1] = lastobj
FileNum[lastobj,2] = fileLevel
REM Fix negative filesize
If fileSize < 0
fileSize = 2147483647 + (fileSize + 2147483648)
ELSE
fileSize = filesize
ENDIF
REM Convert filesize byte to kilobyte
fileSize = fileSize/1000
FileNum[lastobj,3] = fileSize `file size(currentfile$)
`FileNum[lastobj,4] = lastobj `prev directory array address
FileNum[lastobj,5] = 1 `mark this file as indexed
FileNum[lastobj,6] = 1 `mark this file as explored
FileNum[lastobj,7] = 0 `0 = file, 1=folder
FileName$[lastobj,1] = currentfile$
FileName$[lastobj,2] = currentpath$
FileName$[lastobj,3] = prevDir$
SetTextString(lastobj, FileName$[lastobj,1])
SetTextVisible( lastobj, 1 )
CLoseFile(iFileID)
ENDIF
If GetFileCOunt() > 1
currentfile$ = GetNextFile()
endif
Endif `If (t = 1)
`--------------------------------------------------------------------------------------------------------------------------------------------------------------
`Register next files info
If (t > 1)
currentfile$ = currentfile$
iFileID = OpenToRead(currentfile$)
print( currentfile$ )
`pathExist = path exist(baseDir$+"/"+currentfile$)
fileSize = 0
fileSize = GetFileSize(iFileID)
currentpath$ = GetWritePath()
`pathExist = path exist(baseDir$+"/"+currentfile$)
`currentFileType = get file type()
`If current folder is . or .. , skip and open other folder
IF (currentfile$ = "Test File City.agk") or (currentfile$ = "Test File City.exe") or (currentfile$ = "System Volume Information") or (currentfile$ = "main.agc") or (currentfile$ = "FileSearch.agc") or (currentfile$ = "steam_api.dll") or (currentfile$ = "steam_appid.txt")
`Don't do anything
ELSE `if other name, allow set directory
`Register next file in array
lastobj = lastobj + 1
FileNum[lastobj,1] = lastobj
FileNum[lastobj,2] = fileLevel
If fileSize < 0
fileSize = 2147483647 + (fileSize + 2147483648)
ELSE
fileSize = filesize
ENDIF
REM Convert filesize byte to kilobyte
fileSize = fileSize/1000
FileNum[lastobj,3] = fileSize `file size(currentfile$)
`FileNum[lastobj,4] = lastobj `prev directory array address
FileNum[lastobj,5] = 1 `mark this file as indexed
FileNum[lastobj,6] = 1 `mark this file as explored
FileNum[lastobj,7] = 0 `0 = file, 1=folder
FileName$[lastobj,1] = currentfile$
FileName$[lastobj,2] = currentpath$
FileName$[lastobj,3] = prevDir$
SetTextString(lastobj, FileName$[lastobj,1])
SetTextVisible( lastobj, 1 )
CLoseFile(iFileID)
ENDIF
If t < GetFileCOunt()
currentfile$ = GetNextFile()
Endif
Endif `If (t > 1)
NEXT t `FOR t = (1) to (checklist quantity() )
ENDIF `If getfileCount() > 0)
`================================================================================================================================================
`================================================================================================================================================
//Register FOLDERS info in directory
If GetFolderCOunt() > 0
`FOR t = (1) to GetFileCOunt()
FOR t = (1) to GetFolderCOunt()
`Register first file info
If (t = 1)
`GetFirstFile()
currentfile$ = GetFirstFolder()
print( currentfile$ )
currentpath$ = GetWritePath()
`iFileID = OpenToRead(currentfile$)
`pathExist = path exist(baseDir$+"/"+currentfile$)
fileSize = 0
`fileSize = GetFileSize(iFileID)
`If current folder is . or .. , skip and open other folder
IF (currentfile$ = "System Volume Information")
`Don't do anything
ELSE `if other name, allow set directory
REM If current file is not media folder, then register file info
IF (currentfile$ = "media") AND (currentpath$ = "")
ELSE
`Register this file info in array
lastobj = lastobj + 1
FileNum[lastobj,1] = lastobj
FileNum[lastobj,2] = fileLevel
REM Fix negative filesize
If fileSize < 0
fileSize = 2147483647 + (fileSize + 2147483648)
ELSE
fileSize = filesize
ENDIF
REM Convert filesize byte to kilobyte
fileSize = fileSize/1000
FileNum[lastobj,3] = fileSize `file size(currentfile$)
`FileNum[lastobj,4] = lastobj `prev directory array address
FileNum[lastobj,5] = 1 `mark this file as indexed
FileNum[lastobj,6] = 0 `mark this file as explored
FileNum[lastobj,7] = 1 `0 = file, 1=folder
FileName$[lastobj,1] = currentfile$
FileName$[lastobj,2] = currentpath$
FileName$[lastobj,3] = prevDir$
SetTextString(lastobj, FileName$[lastobj,1])
SetTextVisible( lastobj, 1 )
CLoseFile(iFileID)
ENDIF : `IF (currentfile$ = "media") AND (currentpath$ = "")
ENDIF
If GetFolderCOunt() > 1
currentfile$ = GetNextFolder()
endif
Endif `If (t = 1)
`-------------------------------------------------------------------------------------------------------------------------------------------------
`Register next folder info
If (t > 1)
currentfile$ = currentfile$
`iFileID = OpenToRead(currentfile$)
print( currentfile$ )
`pathExist = path exist(baseDir$+"/"+currentfile$)
fileSize = 0
`fileSize = GetFileSize(iFileID)
currentpath$ = GetWritePath()
`pathExist = path exist(baseDir$+"/"+currentfile$)
`currentFileType = get file type()
`If current folder is . or .. , skip and open other folder
IF (currentfile$ = "System Volume Information")
`Don't do anything
ELSE `if other name, allow set directory
REM If current file is not media folder, then register file info
IF (currentfile$ = "media") AND (currentpath$ = "")
ELSE
`Register next file in array
lastobj = lastobj + 1
FileNum[lastobj,1] = lastobj
FileNum[lastobj,2] = fileLevel
If fileSize < 0
fileSize = 2147483647 + (fileSize + 2147483648)
ELSE
fileSize = filesize
ENDIF
REM Convert filesize byte to kilobyte
fileSize = fileSize/1000
FileNum[lastobj,3] = fileSize `file size(currentfile$)
`FileNum[lastobj,4] = lastobj `prev directory array address
FileNum[lastobj,5] = 1 `mark this file as indexed
FileNum[lastobj,6] = 0 `mark this file as explored
FileNum[lastobj,7] = 1 `0 = file, 1=folder
FileName$[lastobj,1] = currentfile$
FileName$[lastobj,2] = currentpath$
FileName$[lastobj,3] = prevDir$
SetTextString(lastobj, FileName$[lastobj,1])
SetTextVisible( lastobj, 1 )
CLoseFile(iFileID)
ENDIF : `IF (currentfile$ = "media") AND (currentpath$ = "")
ENDIF
If t < GetFolderCOunt()
currentfile$ = GetNextFolder()
Endif
Endif `If (t > 1)
NEXT t `FOR t = (1) to (checklist quantity() )
ENDIF `If getfolderCount() > 0)
`================================================================================================================================================
`================================================================================================================================================
```empty checklist
````Set dir baseDir$
````Perform checklist for files
lastArray = lastObj
fileNotMade = lastObj
`fileSearch = 1
`allowMakeBox = 1
`FolderSizeCalculated = 1
ENDFUNCTION
3rd part
Function SearchDrive()
If filesearch = 1
PRINT("FileSearch Searchdrive: " + STR(filesearch) )
`Check if all file explored
fileNotExplored = 0
For y = (terrainNum +1) to lastArray
If (FileNum[y,7] = 1) and (FileNum[y,6] = 0) `if folder not explored, then mark filenotmade as still exist
fileNotExplored = fileNotExplored + 1
Endif
Next y
`Allow make box after all folders explored
If fileNotExplored = 0
allowMakeBox = 1
filesearch = 0
Else
allowMakeBox = 0
filesearch = 1
Endif
If fileNotExplored > 0
fileLevel = fileLevel +1
Endif
`PRINT("FileSearch Searchdrive: " + STR(filesearch) )
IF filesearch = 1
`If fileNotExplored > 0
`fileLevel = fileLevel + 1
`Endif
`Explore folders that was registered in array (will NOT explore unregistered folders)
For x = (terrainNum +1) to lastArray
`If file is a folder and unexplored, then explore the folder
If (FileNum[x,7] = 1) and (FileNum[x,6] = 0)
`IF FileName$[x,1] = "media"
`ELSE
`Catch
PrevDir$ = FileName$[x,2]
`CD FileName$[x,2]+"\"+FileName$[x,1]
`SetFolder("")
SetRawWritePath(FileName$[x,2]+FileName$[x,1])
SetFolder("")
`perform checklist for files
`---------------------------------------------------------------------------------------------------------------------------------------------------------
`Register FILES info
If (filesearch = 1) and (GetFileCOunt() > 0)
FOR t = (1) to (GetFileCOunt() )
`Register first file info
If (t = 1)
`GetFirstFile()
currentfile$ = GetFirstFile()
`currentpath$ = Getfolder()
currentpath$ = GetWritePath()
`pathExist = path exist(get dir$()+"/"+currentfile$)
`currentFileType = get file type()
iFileID = OpenToRead(currentfile$)
`pathExist = path exist(baseDir$+"/"+currentfile$)
fileSize = 0
fileSize = GetFileSize(iFileID)
`If files are not . or .. or invalid files, register files info in array
IF (currentfile$ = "Test File City.agk") or (currentfile$ = "Test File City.exe") or (currentfile$ = "System Volume Information") or (currentfile$ = "main.agc") or (currentfile$ = "FileSearch.agc") or (currentfile$ = "steam_api.dll") or (currentfile$ = "steam_appid.txt")
`Don't do anything
ELSE `if other name, allow explore and set directory
`If currentFileType = 0 or currentFileType = 1
lastobj = lastobj + 1
fileNotMade = fileNotMade + 1
`Endif
FileNum[lastobj,1] = lastobj
FileNum[lastobj,2] = fileLevel
`Calculate real file size
If (fileSize < 0)
fileSize = 2147483647 + (fileSize + 2147483648)
ELSE
fileSize = fileSize
ENDIF
REM Convert filesize byte to kilobyte
fileSize = fileSize/1000
FileNum[lastobj,3] = fileSize `file size(currentfile$)
`FileNum(lastobj,4) = boxmade `boxmade = 1 if box reperesenting this file was made
FileNum[lastobj,5] = 1 `mark file as indexed
FileNum[lastobj,6] = 0 `mark this file NOT explored yet
FileNum[lastobj,7] = 0 `0 = file, 1=folder
FileNum[lastobj,8] = x `record previous file number in the array
FileName$[lastobj,1] = currentfile$
FileName$[lastobj,2] = currentpath$
FileName$[lastobj,3] = prevDir$
ENDIF `IF NOT (currentfile$ = ".") or (currentfile$ = "..")
If (GetFileCOunt() > 1)
currentfile$ = GetNextFile()
endif
Endif `If (t = 1)
`Register next files info
If (t > 1) and (filesearch = 1)
currentfile$ = currentfile$
`currentpath$ = Getfolder()
currentpath$ = GetWritePath()
iFileID = OpenToRead(currentfile$)
fileSize = 0
fileSize = GetFileSize(iFileID)
`newpath$ = currentpath$+currentfile$
`pathExist = path exist (currentpath$+"\"+currentfile$)
`currentFileType = get file type()
`If files are not . or .. or invalid files, register files info in array
IF (currentfile$ = "Test File City.agk") or (currentfile$ = "Test File City.exe") or (currentfile$ = "System Volume Information") or (currentfile$ = "main.agc") or (currentfile$ = "FileSearch.agc") or (currentfile$ = "steam_api.dll") or (currentfile$ = "steam_appid.txt")
`Don't do anything
ELSE `if other name, allow indexing
`If currentFileType = 0 or currentFileType = 1
lastobj = lastobj + 1
fileNotMade = fileNotMade + 1
`Endif
FileNum[lastobj,1] = lastobj
FileNum[lastobj,2] = fileLevel
If (fileSize <0)
fileSize = 2147483647 + (fileSize+2147483648)
ELSE
fileSize = fileSize
ENDIF
REM Convert filesize byte to kilobyte
fileSize = fileSize/1000
FileNum[lastobj,3] = fileSize `file size(currentfile$)
`FileNum[lastobj,4] = boxmade `boxmade = 1 if box reperesenting this file was made
FileNum[lastobj,5] = 1
FileNum[lastobj,6] = 0 `mark this file NOT explored yet
FileNum[lastobj,7] = 0 `0 =file, 1 = folder
FileNum[lastobj,8] = x `record previous file number in the array
FileName$[lastobj,1] = currentfile$
FileName$[lastobj,2] = currentpath$
FileName$[lastobj,3] = prevDir$
ENDIF `IF (currentfile$ = ".") or (currentfile$ = "..")
If (t < GetFileCOunt())
currentfile$ = GetNextFile()
Endif
Endif `If (t > 1) and (filesearch = 1)
NEXT t `FOR t = (1) to (checklist quantity() )
`empty checklist
`ENDIF
ENDIF `If (filesearch = 1) and (checklist quantity() > 0)
`ENDCATCH
`==========================================================================================================================================================================
`Register FOLDERs info
If (filesearch = 1) and (GetFolderCOunt() > 0)
FOR f = (1) to (GetFolderCOunt() )
`Register first file info
If (f = 1)
`GetFirstFile()
currentfile$ = GetFirstFolder()
`currentpath$ = Getfolder()
currentpath$ = GetWritePath()
`pathExist = path exist(get dir$()+"/"+currentfile$)
`currentFileType = get file type()
`iFileID = OpenToRead(currentfile$)
`pathExist = path exist(baseDir$+"/"+currentfile$)
fileSize = 0
`fileSize = GetFileSize(iFileID)
`If files are not . or .. or invalid files, register files info in array
IF (currentfile$ = "System Volume Information")
`Don't do anything
ELSE `if other name, allow explore and set directory
REM If current file is not media folder, then register file info
IF (currentfile$ = "media") AND (currentpath$ = "")
ELSE
`If currentFileType = 0 or currentFileType = 1
lastobj = lastobj + 1
fileNotMade = fileNotMade + 1
`Endif
FileNum[lastobj,1] = lastobj
FileNum[lastobj,2] = fileLevel
`Calculate real file size
If (fileSize < 0)
fileSize = 2147483647 + (fileSize + 2147483648)
ELSE
fileSize = fileSize
ENDIF
REM Convert filesize byte to kilobyte
fileSize = fileSize/1000
FileNum[lastobj,3] = fileSize `file size(currentfile$)
`FileNum(lastobj,4) = boxmade `boxmade = 1 if box reperesenting this file was made
FileNum[lastobj,5] = 1 `mark file as indexed
FileNum[lastobj,6] = 0 `mark this file NOT explored yet
FileNum[lastobj,7] = 1 `0 = file, 1=folder
FileNum[lastobj,8] = x `record previous file number in the array
FileName$[lastobj,1] = currentfile$
FileName$[lastobj,2] = currentpath$
FileName$[lastobj,3] = prevDir$
ENDIF
ENDIF `IF NOT (currentfile$ = ".") or (currentfile$ = "..")
If (GetFolderCOunt() > 1)
currentfile$ = GetNextFolder()
endif
Endif `If (f = 1)
`Register next files info
If (f > 1) and (filesearch = 1)
currentfile$ = currentfile$
`currentpath$ = Getfolder()
currentpath$ = GetWritePath()
`iFileID = OpenToRead(currentfile$)
fileSize = 0
`fileSize = GetFileSize(iFileID)
`newpath$ = currentpath$+currentfile$
`pathExist = path exist (currentpath$+"\"+currentfile$)
`currentFileType = get file type()
`If files are not . or .. or invalid files, register files info in array
IF (currentfile$ = "System Volume Information")
`Don't do anything
ELSE `if other name, allow indexing
REM If current file is not media folder, then register file info
IF (currentfile$ = "media") AND (currentpath$ = "")
ELSE
`If currentFileType = 0 or currentFileType = 1
lastobj = lastobj + 1
fileNotMade = fileNotMade + 1
`Endif
FileNum[lastobj,1] = lastobj
FileNum[lastobj,2] = fileLevel
If (fileSize <0)
fileSize = 2147483647 + (fileSize+2147483648)
ELSE
fileSize = fileSize
ENDIF
REM Convert filesize byte to kilobyte
fileSize = fileSize/1000
FileNum[lastobj,3] = fileSize `file size(currentfile$)
`FileNum[lastobj,4] = boxmade `boxmade = 1 if box reperesenting this file was made
FileNum[lastobj,5] = 1 `mark file as indexed
FileNum[lastobj,6] = 0 `mark this file NOT explored yet
FileNum[lastobj,7] = 1 `0 =file, 1 = folder
FileNum[lastobj,8] = x `record previous file number in the array
FileName$[lastobj,1] = currentfile$
FileName$[lastobj,2] = currentpath$
FileName$[lastobj,3] = prevDir$
ENDIF
ENDIF `IF (currentfile$ = ".") or (currentfile$ = "..")
If (f < GetFolderCOunt())
currentfile$ = GetNextFolder()
Endif
Endif `If (f > 1) and (filesearch = 1)
NEXT f `FOR f = (1) to (checklist quantity() )
`empty checklist
ENDIF `If (filesearch = 1) and (checklist quantity() > 0)
`==========================================================================================================================================================================
Endif `If file is a folder and unexplored
`ENDIF : `IF fileName$ NOT media
FileNum[x,6] = 1 `mark folder as explored
NEXT x `For x = (endObj +1) to lastArray
lastArray = lastobj
ENDIF `If filesearch = 1
ENDIF `If filesearch =1
`==============================================================================================================================================================================
`Calculate folder sizes
`Calculate individual folder sizes
IF (filesearch = 0) and (allowMakeBox = 1) and (FolderSizeCalculated = 0)
FOR s = (terrainNum +1) to lastobj
IF (FileNum[s,7] = 0) `If file, then add this file size to previous folder size
prevFolder = FileNum[s,8]
FileNum[prevFolder,3] = FileNum[prevFolder,3] + FileNum[s,3]
remstart
For t = (endObj +1) to lastobj
`If directory of the folder + folder name = current file directory
If (FileName$(t,2)+"\"+FileName$(t,1)) = FileName$(s,2)
`folder size = folder size + file size it contain
FileNum(t,3) = FileNum(t,3) + FileNum(s,3)
Endif
NEXT
remend
ENDIF
NEXT s
`Pass folder sizes to previous folders - start calculation from last array, work up to biggest/base folders
FOR s = lastobj to (terrainNum +1) STEP -1
IF (FileNum[s,7] = 1) `If folder
prevFolder = FileNum[s,8]
FileNum[prevFolder,3] = FileNum[prevFolder,3] + FileNum[s,3]
remstart
For t = (endObj +1) to lastobj
`If directory of the folder + folder name = current file directory
If (FileName$(t,2)+"\"+FileName$(t,1)) = FileName$(s,2)
`folder size = folder size + file size it contain
FileNum(t,3) = FileNum(t,3) + FileNum(s,3)
Endif
NEXT
remend
ENDIF
NEXT s
FolderSizeCalculated = 1
ENDIF
ENDFUNCTION