Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Kill a directory in DOS
#16
(11-30-2023, 05:13 AM)eoredson Wrote:
(11-30-2023, 05:10 AM)SMcNeill Wrote:
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.
Very well stated! That is what I was starting to do..

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:


Attached Files
.h   direntry.h (Size: 1.15 KB / Downloads: 26)
Reply


Messages In This Thread
Kill a directory in DOS - by eoredson - 11-30-2023, 04:16 AM
RE: Kill a directory in DOS - by TerryRitchie - 11-30-2023, 04:26 AM
RE: Kill a directory in DOS - by eoredson - 11-30-2023, 04:35 AM
RE: Kill a directory in DOS - by TerryRitchie - 11-30-2023, 04:38 AM
RE: Kill a directory in DOS - by eoredson - 11-30-2023, 04:44 AM
RE: Kill a directory in DOS - by TerryRitchie - 11-30-2023, 04:47 AM
RE: Kill a directory in DOS - by eoredson - 11-30-2023, 04:50 AM
RE: Kill a directory in DOS - by SMcNeill - 11-30-2023, 04:53 AM
RE: Kill a directory in DOS - by eoredson - 11-30-2023, 04:58 AM
RE: Kill a directory in DOS - by SMcNeill - 11-30-2023, 05:01 AM
RE: Kill a directory in DOS - by SMcNeill - 11-30-2023, 04:59 AM
RE: Kill a directory in DOS - by eoredson - 11-30-2023, 05:03 AM
RE: Kill a directory in DOS - by mnrvovrfc - 11-30-2023, 06:58 AM
RE: Kill a directory in DOS - by SMcNeill - 11-30-2023, 05:10 AM
RE: Kill a directory in DOS - by eoredson - 11-30-2023, 05:13 AM
RE: Kill a directory in DOS - by SMcNeill - 11-30-2023, 05:40 AM
RE: Kill a directory in DOS - by TerryRitchie - 11-30-2023, 05:37 AM
RE: Kill a directory in DOS - by eoredson - 11-30-2023, 05:40 AM
RE: Kill a directory in DOS - by TerryRitchie - 11-30-2023, 06:36 AM
RE: Kill a directory in DOS - by eoredson - 11-30-2023, 06:07 AM
RE: Kill a directory in DOS - by SMcNeill - 11-30-2023, 06:30 AM
RE: Kill a directory in DOS - by eoredson - 11-30-2023, 06:44 AM
RE: Kill a directory in DOS - by SMcNeill - 11-30-2023, 06:44 AM
RE: Kill a directory in DOS - by mnrvovrfc - 11-30-2023, 07:08 AM
RE: Kill a directory in DOS - by SpriggsySpriggs - 11-30-2023, 12:22 PM
RE: Kill a directory in DOS - by grymmjack - 11-30-2023, 12:48 PM
RE: Kill a directory in DOS - by SMcNeill - 11-30-2023, 02:17 PM
RE: Kill a directory in DOS - by mnrvovrfc - 11-30-2023, 02:35 PM
RE: Kill a directory in DOS - by Kernelpanic - 11-30-2023, 09:05 PM
RE: Kill a directory in DOS - by SMcNeill - 11-30-2023, 09:25 PM
RE: Kill a directory in DOS - by eoredson - 12-01-2023, 06:54 AM



Users browsing this thread: 33 Guest(s)