|
|
Back to UserFriendly Strip Comments Index
|
Any DOS batch gurus around? | by Naruki | 2003-09-06 15:29:38 |
|
Thanks for the comments, everyone! | by Naruki | 2003-09-06 18:21:47 |
| Am I too late to chip in? |
by ragman |
2003-09-06 20:43:05 |
Working in batch limits you greatly. And the "dir" command varies a lot between versions of Windows, so it's not surprising that some of the suggestions didn't quite work.
I'm a little rusty on my DOS batch, so I don't know if what I'm suggesting would work. I think it will, but it's a little clunky.
First, do a "dir /ad" on your folder to get a list of everything. Your list would be something like this (which I did on an XP machine):
Directory of C:\junk
09/06/2003 10:12 PM <DIR> .
09/06/2003 10:12 PM <DIR> ..
09/06/2003 10:12 PM <DIR> one
09/06/2003 10:12 PM <DIR> three
09/06/2003 10:13 PM <DIR> two
0 File(s) 0 bytes
Directory of C:\junk\one
09/06/2003 10:12 PM <DIR> .
09/06/2003 10:12 PM <DIR> ..
0 File(s) 0 bytes
Directory of C:\junk\three
09/06/2003 10:12 PM <DIR> .
09/06/2003 10:12 PM <DIR> ..
0 File(s) 0 bytes
Directory of C:\junk\two
09/06/2003 10:13 PM <DIR> .
09/06/2003 10:13 PM <DIR> ..
09/06/2003 10:13 PM 5 two.txt
09/06/2003 10:13 PM <DIR> twoa
09/06/2003 10:13 PM <DIR> twob
1 File(s) 5 bytes
Directory of C:\junk\two\twoa
09/06/2003 10:13 PM <DIR> .
09/06/2003 10:13 PM <DIR> ..
0 File(s) 0 bytes
Directory of C:\junk\two\twob
09/06/2003 10:13 PM <DIR> .
09/06/2003 10:13 PM <DIR> ..
09/06/2003 10:13 PM 5 twob.txt
1 File(s) 5 bytes
Total Files Listed:
2 File(s) 10 bytes
17 Dir(s) 59,597,053,952 bytes free
I can't remember of DOS batch would read the results of your "dir /ad" command into something you could loop thru later, so you might have to redirect the results into a separate file that would serve as the driver part of the delete portion of your process.
The second part steps thru the list from the first part. When you find a "Directory of" line, you initialize your counter and save the path name.
Count the nonblank lines until you get to a "File(s)" line. If your number is greater than two, the directory is not empty. It could contain files or other directories. If the number is two (or less), you know you can remove it.
The flaw in this method is that it won't clean up a parent directory whose child directories are also empty. If you were using something other than DOS batch, I would suggest calling the delete routine recursively, drilling down to the lowest levels. Or you could figure out how to work from the lowest child directory first, and work backwards up thru the structure so that all children are deleted by the time you get to the top.
Perhaps that could be done by a third, intermediary step in the middle that would allow you to sort the directory list in blocks, but that would get ugly.
A better way might be to make it a three-pass process. The second pass counts folders like I described, but dumps the counts and paths into yet another temp file. This file could be the one that the "rd" command could be executed on.
Hope this helps. I have an ancient version of ObjRexx that I've run on my older Windows machines, but not on XP, so I don't know if that would work. It would be infinitely better than DOS batch and its executables are pretty portable (I used to install it on my machines whenever I started a new job. REXX was one of the cool things about OS/2).
Good luck. |
|
[ Reply ] |
|
I'm wondering how your DIR command did that. | by Naruki | 2003-09-06 22:26:39 |
|
Forgot the /s in my description. | by ragman | 2003-09-07 00:40:57 |
|
|
[Todays Cartoon Discussion]
[News Index]
|
|