Hi! :) I wrote a small function which SHOULD grab the name of each file / folder (the user can select whether or not this includes file / folder incursion counting or just regular counting of files / folders in one folder directory), from the folder, and display it. Problem is, it's returning literally nothing at all (""). What am I doing wrong, here?
The problem is in the function I wrote, called "Grab_File_Names$(folder$, iwantfolder=0, iwantfiles=1)".
The function that allows CountDirs() & CountFiles() to return a value higher than or equal to 0, are because ScanDir() grabs the count of folders / files (incursively or not).
The functions:
Global DirCount, FileCount
Function Count_Dirs()
Return DirCount
End Function
Function Count_Files()
Return FileCount
End Function
Function Grab_File_Names$(folder$, iwantfolder=0, iwantfiles=1)
myDir=ReadDir(folder$)
Repeat
file$=NextFile$(myDir)
If file$="" Then Exit
If iwantfolder = 1 And iwantfiles = 0
If Count_Dirs()<>0
If file$<>"." And file$<>".." Then
filenames$ = file$
If filenames$<>""
api_MessageBox(0, filenames$, "INFO", 0)
EndIf
EndIf
Exit
Else
Exit
EndIf
Else If iwantfolder = 0 And iwantfiles = 1
If Count_Files()<>0
If file$<>"." And file$<>".." Then
filenames$ = file$
If filenames$<>""
api_MessageBox(0, filenames$, "INFO", 0)
EndIf
EndIf
Exit
Else
Exit
EndIf
EndIf
Forever
Return filenames$
End Function
Function ScanDir(folder$, recursive=1)
If (recursive = 0 Or recursive = 1)
myDir=ReadDir(folder$)
Repeat
file$=NextFile$(myDir)
If file$="" Then Exit
If FileType(folder$+"\"+file$) = 2 Then
If file$<>"." And file$<>".." Then
If recursive Then ScanDir(folder$+"\"+file$)
DirCount=DirCount+1
EndIf
Else
FileCount=FileCount+1
End If
Forever
CloseDir myDir
Else
api_MessageBox(0, "You can't get away with that!", "WARNING!", 0)
End
EndIf
End Function
Thank You!
|