Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deleting Folders in QB
#1
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...
Reply
#2
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►
Reply
#3
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] "
Reply
#4
That won't work in my computer, as my switch would be /s. In spanish, "Yes" is "Si", and they translated the OS... Tongue
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#5
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.
Reply
#6
Quote:That won't work in my computer, as my switch would be /s. In spanish, "Yes" is "Si", and they translated the OS... Tongue

Ahh. So in that case, Rockuman's harddrive deleting virus wouldnt work in Spain. Fair enough. Tongue

:rotfl:
Reply
#7
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.
Reply
#8
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
Reply
#9
(oops...I didn't see that)
Sorry...stupid me. Tongue
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#10
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)