Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Kill a directory in DOS
#11
(11-30-2023, 04:58 AM)eoredson Wrote:
(11-30-2023, 04:53 AM)SMcNeill Wrote:
(11-30-2023, 04:50 AM)eoredson Wrote: I am running QB64 yes.

I think this is a bad thread..

https://qb64phoenix.com/qb64wiki/index.php/RMDIR
So, I should shell to RMDIR?

Why would you need to shell??   RMDIR is a built in QB64 command, just as KILL is.   Are we on the same page here??   You *ARE* asking how to use QB64 to remove directories, right??
Reply
#12
Deltree does not exist in Cmd.exe

What I am trying to do:

Code: (Select All)
Print "Enter dir spec:";
Input Dir$
If _DirExists(Dir$) Then
   Kill Dir$
End If

But it has to be backwards compatible with QB1, QB4, and QB7..
Reply
#13
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.
Reply
#14
(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...
Reply
#15
Hold the phone, I'm still stuck on the QB64 in the Dosbox thing. Compiled QB64 programs will not run in Dosbox. Dosbox emulates 16bit architecture.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#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
#17
(11-30-2023, 05:37 AM)TerryRitchie Wrote: Hold the phone, I'm still stuck on the QB64 in the Dosbox thing. Compiled QB64 programs will not run in Dosbox. Dosbox emulates 16bit architecture.

Ok. I am using QB64 for a directory delete function and it is compatible with QB1, 4, and 7 in Dosbox-x.

Does that make sense?? All I want to do is Kill Dir$
Reply
#18
Hey. I got an idea for the makers of QB64pe:

Maybe you could add a KillDir(Dir$) function!?
Reply
#19
(11-30-2023, 06:07 AM)eoredson Wrote: Hey. I got an idea for the makers of QB64pe:

Maybe you could add a KillDir(Dir$) function!?

That's what RMDIR does for you.  It's just up to you to make certain the directory is empty, or use the function I provided above.
Reply
#20
(11-30-2023, 05:40 AM)eoredson Wrote:
(11-30-2023, 05:37 AM)TerryRitchie Wrote: Hold the phone, I'm still stuck on the QB64 in the Dosbox thing. Compiled QB64 programs will not run in Dosbox. Dosbox emulates 16bit architecture.

Ok. I am using QB64 for a directory delete function and it is compatible with QB1, 4, and 7 in Dosbox-x.

Does that make sense?? All I want to do is Kill Dir$
Nope, still doesn't make sense to me. The code provided by Steve will not work in anything except QB64. You need to write your code using QuickBasic 4.5 inside of DosBox. If Dosbox supports DELTREE then you can shell to that.

Even if QB64 did include a KillDir command as you requested what good would that do you in Dosbox? QuickBasic would look at that command and error.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply




Users browsing this thread: 2 Guest(s)