11-30-2023, 05:40 AM
(11-30-2023, 05:13 AM)eoredson Wrote:(11-30-2023, 05:10 AM)SMcNeill Wrote:Very well stated! That is what I was starting to do..Code: (Select All)Print "Enter dir spec:";
Input Dir$
If _DirExists(Dir$) Then
RmDir Dir$
End If
If the directory isn't empty, then you'll need to write a routine to change to get the files in that directory, KILL them, and then RMDIR that directory. If there's directories inside that directory and not just files, then you'll want that routine to work recursively.
Could you write one?? It would have to be internal without any shell.
Given the two functions Kill and RMdir it could be done...
Sure, and it only takes a few minutes to do so:
Code: (Select All)
CONST Testing = 0
RMDIR_Recursive "Z:\"
SUB RMDIR_Recursive (Dir$)
IF RIGHT$(Dir$, 1) = "\" OR RIGHT$(Dir$, 1) = "/" THEN Dir$ = LEFT$(Dir$, LEN(Dir$) - 1)
IF _DIREXISTS(Dir$) = 0 THEN EXIT SUB
REDIM FileList(0) AS STRING
GetFileList Dir$, FileList()
FOR i = 1 TO UBOUND(FileList)
IF FileList(i) <> "." AND FileList(i) <> ".." THEN
$IF WIN THEN
file$ = Dir$ + "\" + FileList(i)
$ELSE
file$ = Dir$ + "/" + FileList(i)
$END IF
IF _FILEEXISTS(file$) THEN
IF Testing THEN PRINT "DEL "; file$ ELSE KILL file$
ELSEIF _DIREXISTS(file$) THEN
RMDIR_Recursive file$
END IF
END IF
NEXT
IF LEN(Dir$) > 3 THEN
IF Testing THEN PRINT "RD "; Dir$ ELSE RMDIR Dir$
END IF
END SUB
SUB GetFileList (SearchDirectory AS STRING, FileList() AS STRING)
DECLARE CUSTOMTYPE LIBRARY ".\direntry"
FUNCTION load_dir& (s AS STRING)
FUNCTION has_next_entry& ()
SUB close_dir ()
SUB get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
END DECLARE
DIM flags AS LONG, file_size AS LONG
REDIM _PRESERVE FileList(1000)
FileCount = 0
IF load_dir(SearchDirectory) THEN
DO
length = has_next_entry
IF length > -1 THEN
nam$ = SPACE$(length)
get_next_entry nam$, flags, file_size
FileCount = FileCount + 1
IF FileCount > UBOUND(FileList) THEN REDIM _PRESERVE FileList(UBOUND(FileList) + 100)
FileList(FileCount) = nam$
END IF
LOOP UNTIL length = -1
close_dir
ELSE
END IF
REDIM _PRESERVE FileList(FileCount)
END SUB
And the file which you need to put in the QB64 folder to run with this -- direntry.h: