Posts: 1,556
Threads: 298
Joined: Dec 2002
For goodness sakes, don't ask why I wanna know...
How would I delete an entire folder through QB?
I tried Shell "del", but that didn't work...
Posts: 2,771
Threads: 96
Joined: Oct 2003
Errr... check RMDIR:
Quote:âQuickSCREEN⺠âDetails⺠âExample⺠âContents⺠âIndexâº
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
RMDIR - a statement that interfaces with DOS to remove an existing
directory
Syntax
RMDIR pathspec
â pathspec is a string expression that identifies the directory
to be removed
See Also âMKDIR⺠âCHDIRâº
Posts: 1,272
Threads: 36
Joined: Feb 2003
But to use that the directory must be empty.
To delete any directory, do this: Code: SHELL "deltree path\dirname /y"
Without the /y, it'll ask "Delete directory "dirname" and all it's subdirectories? [yn] "
Posts: 6,419
Threads: 74
Joined: Mar 2002
That won't work in my computer, as my switch would be /s. In spanish, "Yes" is "Si", and they translated the OS...
Posts: 3,522
Threads: 189
Joined: Dec 2003
Make a recursive function...
[pseudo code]
shell dir [with the dir only switch] > afile (note, afile must be a random filename as this is a recursive function, use afile$=hex$(10000*rnd) or something)
open afile and read it
do
go into the first dir (shell "cd "+dirname$
call this function
remove all files in dir (kill *.*)
go back (shell cd..)
remove dir (rmdir)
loop until eof(afile)
close afile
kill afile
[/pseudo code]
I don't think that the DIR switches (when it comes to sorting order /ogn) or displaying info one page at a time (/P) is translated
a good method to retreive all files and dirs in the current folder is:
SHELL "DIR /-p/-w/ogn/-s/b/-v/-4 " + mask$ + " > temp.tmp"
where mask$ is the dir mask (*nana; *.exe aso)
he open the file and there you have it, a nice long list of the curent directories content.
I dont know if this works under XP thouh, but I can't see any reason why it shouldnt.
Try: DIR /? to get a list of possible switches, a good idea is to disable any switches you dont use, like you don't want your progam to halt every page when you are writing to a file, so you add /-p to disable it.
Posts: 2,771
Threads: 96
Joined: Oct 2003
Quote:That won't work in my computer, as my switch would be /s. In spanish, "Yes" is "Si", and they translated the OS...
Ahh. So in that case, Rockuman's harddrive deleting virus wouldnt work in Spain. Fair enough.
:rotfl:
Posts: 3,616
Threads: 287
Joined: Jan 2003
No use making your own recursive function...use MSDOS's.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 3,522
Threads: 189
Joined: Dec 2003
Yes Zack, care to explain? :lol:
There is no pure DOS way of doing it, there is always the translation issue.
Deltree nana
Ãr du säker pÃ¥ att du vill ta bort nana och hela innehÃ¥llet [J/N]
My switch would be | j
Posts: 3,616
Threads: 287
Joined: Jan 2003
( oops...I didn't see that)
Sorry...stupid me.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 1,752
Threads: 21
Joined: Jun 2002
Shelling sucks.
Code: ' Deletes a directory and all files and
' subdirectories within it.
' (use with caution!)
'
' by Plasma
DEFINT A-Z
'$INCLUDE: 'QB.BI'
DECLARE FUNCTION DelTree$ (Directory$)
DECLARE FUNCTION DIR2$ (FileSpec$, Attr)
DECLARE SUB SetAttr (File$, Attr)
DIM SHARED DTA AS STRING * 44
' Example:
'rc$ = DelTree$("C:\TEMP")
'
' (rc$ is just a dummy variable,
' the function will return a null string)
FUNCTION DelTree$ (Directory$)
DIM SaveDTA AS STRING * 44
IF RIGHT$(Directory$, 1) <> "\" THEN Directory$ = Directory$ + "\"
'look for files in this dir first
'remove attributes and then delete them
FoundFile$ = DIR2$(Directory$ + "*.*", &H27)
DO WHILE LEN(FoundFile$)
SetAttr Directory$ + FoundFile$, &H0
KILL Directory$ + FoundFile$
FoundFile$ = DIR2$("", &H27)
LOOP
'get a list of dirs in this dir and recurse them
FoundDir$ = DIR2$(Directory$ + "*.*", &H17)
DO WHILE FoundDir$ <> ""
IF FoundDir$ <> "." AND FoundDir$ <> ".." THEN
SaveDTA = DTA
Recurse$ = DelTree$(Directory$ + FoundDir$ + "\")
DTA = SaveDTA
IF Recurse$ <> "" THEN
DelTree$ = Recurse$
EXIT FUNCTION
END IF
END IF
FoundDir$ = DIR2$("", &H17)
LOOP
'all files and directories from this directory have been
'deleted, so we can go ahead and delete this directory
IF (Directory$ <> "\") AND (RIGHT$(Directory$, 2) <> ":\") THEN
SetAttr LEFT$(Directory$, LEN(Directory$) - 1), &H10
RMDIR LEFT$(Directory$, LEN(Directory$) - 1)
END IF
DelTree$ = ""
END FUNCTION
SUB SetAttr (File$, Attr)
FileZ$ = File$ + CHR$(0)
DIM Regs AS RegTypeX
Regs.ax = &H4301
Regs.cx = Attr
Regs.ds = VARSEG(FileZ$)
Regs.dx = SADD(FileZ$)
InterruptX &H21, Regs, Regs
END SUB
FUNCTION DIR2$ (FileSpec$, Attr)
'Settings for Attr: (may be combined)
'
' &H40 Device
' &H20 Archive
' &H10 Directory
' &H8 Volume Label
' &H4 System File
' &H2 Hidden File
' &H1 Read-Only File
FileSpecZ$ = FileSpec$ + CHR$(0)
DO
DIM Regs AS RegTypeX
Regs.ax = &H1A00
Regs.ds = VARSEG(DTA)
Regs.dx = VARPTR(DTA)
InterruptX &H21, Regs, Regs
IF FileSpecZ$ <> CHR$(0) THEN
Regs.ax = &H4E00
Regs.cx = Attr
Regs.ds = VARSEG(FileSpecZ$)
Regs.dx = SADD(FileSpecZ$)
ELSE
Regs.ax = &H4F00
END IF
InterruptX &H21, Regs, Regs
IF Regs.flags AND 1 THEN
DIR2$ = ""
EXIT FUNCTION
ELSE
RealAttr = ASC(MID$(DTA, 22, 1))
IF RealAttr AND Attr THEN
Null = INSTR(31, DTA, CHR$(0))
DIR2$ = MID$(DTA, 31, Null - 31)
EXIT FUNCTION
ELSE
FileSpecZ$ = CHR$(0)
END IF
END IF
LOOP
END FUNCTION
|