Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Kill a directory in DOS
#27
Old Skool coding here!

Code: (Select All)
$CONSOLE:ONLY

CONST Test = 1

RD_OldSkool "z:"





SUB RD_OldSkool (Dir$)

    Dir$ = UCASE$(Dir$) 'old skool file names could only be ALL CAPS
    IF RIGHT$(Dir$, 1) <> "\" THEN Dir$ = Dir$ + "\" 'coding this dor windows only.  Make changes as necessary for Linux/Mac slashes and such
    'Note that the UCASE$ line probably won't work with Linux/MAc as well, as they hold uppercase/lowercase to be case specific

    SHELL "cd > TEMP.TXT"
    OPEN "TEMP.TXT" FOR INPUT AS #1
    INPUT #1, Old_Dir$ 'get the old directory name
    CLOSE #1

    CHDIR Dir$ 'change to the specified directory
    SHELL "cd > TEMP.TXT"
    OPEN "TEMP.TXT" FOR INPUT AS #1
    INPUT #1, Verify_Dir$ 'get the changed directory name
    CLOSE #1

    Verify_Dir$ = UCASE$(Verify_Dir$)
    IF RIGHT$(Verify_Dir$, 1) <> "\" THEN Verify_Dir$ = Verify_Dir$ + "\" 'make certain it matchs old skool formatting before verifying

    IF UCASE$(Verify_Dir$) <> Dir$ THEN 'verify that we're in the proper directory now
        PRINT "ERROR: INVALID DIRECTORY!" 'if not, then error and die
        BEEP
        END
    END IF

    SHELL "dir /b /ad > TEMP.TXT"

    OPEN "TEMP.TXT" FOR INPUT AS #1 'can't use BINARY as we're going old skool!
    IF LOF(1) THEN 'If there's any data in that file and it's not just blank
        REDIM DirList(10000) AS STRING 'If you have more than 10,000 directories on an old skool folder, you fail!
        DO
            i = i + 1
            LINE INPUT #1, DirList(i)
        LOOP UNTIL EOF(1)
        REDIM _PRESERVE DirList(i) AS STRING 'free up unused memory in that array of dir lists
    END IF
    CLOSE #1
    FOR j = 1 TO i
        IF DirList(j) <> "." AND DirList(j) <> ".." THEN
            Sub_Dir$ = Dir$ + DirList(j) + "\"
            RD_OldSkool Sub_Dir$
        END IF
    NEXT


    OPEN "TEMP.TXT" FOR OUTPUT AS #1: CLOSE #1 'make certain there's a TEMP.TXT in the file list to clean up automatically
    SHELL "dir /b *.* > TEMP.TXT"
    OPEN "TEMP.TXT" FOR INPUT AS #1
    IF LOF(1) THEN
        DO
            LINE INPUT #1, File$
            PRINT File$, "TEMP.TXT"
            IF File$ <> "TEMP.TXT" THEN 'can't kill our open file!
                IF Test THEN PRINT "Kill: "; File$ ELSE KILL File$
            END IF
        LOOP UNTIL EOF(1)
    END IF
    CLOSE #1
    KILL "TEMP.TXT" 'now kill that file!
    CHDIR Old_Dir$
    FOR i = 65 TO 90
        Test_Dir$ = CHR$(i) + ":\"
        IF Old_Dir$ = Test_Dir$ THEN EXIT SUB
    NEXT
    IF Test THEN PRINT "RMDIR "; Dir$ ELSE RMDIR Dir$
END SUB

I believe every command in this little RD routine works in QB45 and lower.  It also works in QB64 -- well, the Windows version of QB64.  QB45 never ran on Linux or Mac, so it never followed their rules for slashes and filenames and such, so I certainly didn't bother to write this with those particulars in mind.

As before, I left a TEST variable for anyone who just wants to test this out.  (Make it any non-zero value.)  And, as before, I take **ZERO** responsibility if you point it to some folder/drive and erase it off the face of the earth.  Use this at your own risk!  Recursive File/Folder deletion isn't something suitable for most folks to run like this, and this DOES NOT move anything to the Recycle Bin.  This ZAPS things to oblivion, making them lost forever more.  (Unless you want to spend time and effort running some snazzy file recovery software to look for lost data on a drive and restore it.  NOTE -- I WILL NOT HELP WITH ANY RESTORATION NEEDS FOR LOST DATA!!  You have been warned here first, and repeatedly!)
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: 18 Guest(s)