|
|
|
DOS batch file for deleting folders
|
Original Message
|
Name: Teasdam
Date: December 31, 2003 at 13:10:40 Pacific
Subject: DOS batch file for deleting folders OS: Windows XP Pro ver 2002 CPU/Ram: P4 1.5/256
|
Comment: I have 3000+ folders with unique names, each with several common subfolders within them. What I would like is a batch file that could look in a particular subfolder of each parent folder, and check if there are any relevant files there. If there are no relevant files in that subfolder, it would then delete the entire folder. for example... C:\BobJones\ address\ phonenumber\ dob\ I need it to check the "address" subfolder for files with "home" in the name. If there are no such files, it would delete the whole BobJones folder. After that, it would continue to do the same for all other folders. I've been looking into DOS scripting info in the internet but that's all over my head. (This is for an agricultural database and everyone knows farmers and computers don't mix well.)
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Code One
Date: January 3, 2004 at 10:44:49 Pacific
Subject: DOS batch file for deleting folders
|
Reply: (edit)this is a rather complicated code. I admit this has been driving me crazy...worse than I already am. As far as I can gather, you would need to setup either a FIND command or IF. Im not sure yet. Perhaps it's better you manually delete these. I know 3000 files to root threw is a heck of alot, but for now that's your only option. If I get something coded up, I'll send it your way. good day code one
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: FishMonger
Date: January 3, 2004 at 15:33:32 Pacific
Subject: DOS batch file for deleting folders |
Reply: (edit)This is very easy to do, using a Perl script. I'd need to have a few more details and do some testing, but I'd say we can do it with about 12 (or fewer) lines of code.
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: dtech10
Date: January 4, 2004 at 07:08:50 Pacific
Subject: DOS batch file for deleting folders |
Reply: (edit)Hi Teasdam You could try something this, but be careful deltree is a powerfull command. I advise you to change line 2 to this so that you can check it's working ok at first. for /f "tokens=2 delims=\" %%a in (dirs.tmp) do echo "deltree" %%a > nul ================================================= @echo off dir /s /b | find "address\" | find "home" > dirs.tmp for /f "tokens=2 delims=\" %%a in (dirs.tmp) do echo y | deltree %%a > nul del dirs.tmp ==================================================
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: dtech10
Date: January 4, 2004 at 07:26:59 Pacific
Subject: DOS batch file for deleting folders |
Reply: (edit)Hi Teasdam Delete the ">nul" from the test line or you won't see a thing ie. for /f "tokens=2 delims=\" %%a in (dirs.tmp) do echo "deltree" %%a
Report Offensive Follow Up For Removal
|
|
Response Number 5
|
Name: dtech10
Date: January 5, 2004 at 05:17:34 Pacific
Subject: DOS batch file for deleting folders |
Reply: (edit)Hi Teasdam I forgot to include the option in the find command. change this line. dir /s /b | find "address\" | find "home" > dirs.tmp to this dir /s /b | find "address\" | find /v "home" > dirs.tmp
Report Offensive Follow Up For Removal
|
|
Response Number 6
|
Name: Teasdam
Date: January 5, 2004 at 08:04:05 Pacific
Subject: DOS batch file for deleting folders
|
Reply: (edit)I copied a few folders from the server so I could test this on my own computer. At first the find command wasn't pulling out all the needed files for dirs.tmp. There were some case issues so I tried the /I switch and it seems to be working now. I also removed the /v switch but hey I can always put it back...can you tell me what it does? the computer didn't recognize the deltree command so I downloaded one from the internet...no idea what version or anything. However, the deltree portion of the batch file doesn't seem to be doing anything. No errors, but no deletions either. That whole "for" line makes no sense to me so I don't know if I need to try different deltree perhaps?
Report Offensive Follow Up For Removal
|
|
Response Number 7
|
Name: Teasdam
Date: January 5, 2004 at 11:54:36 Pacific
Subject: DOS batch file for deleting folders
|
Reply: (edit)So anyway, here's a real example of what I'm trying to do. The dirs.tmp file is coming out something like this.... C:\customer_files\Jones_Bob-------05340\Plan_Reports\ConservationPlan.xls C:\customer_files\Smith_Bob-------06221\Plan_Reports\CRPplan.xls So the program then needs to pick out the folders that did _not_ have any files under Plan_Reports with "plan" in the name and deltree those. (The thought behind this is the assumption that customer folders with no files with "plan" in the name are inactive, incomplete, or otherwise useless and need to be deleted.)
Report Offensive Follow Up For Removal
|
|
Response Number 8
|
Name: Teasdam
Date: January 5, 2004 at 13:26:14 Pacific
Subject: DOS batch file for deleting folders
|
Reply: (edit)Argh! I've been tinkering, but the problem I keep running into is that with dir /s, every customer has a Plan_Reports line. So here's what I'm thinking... It is very easy to get a list of customers that _do_ have a "plan" file. Now lets say we make another list of all the customers (i.e. dir), then "subtract" the names on the first list from the second. This would give me a list of customers who _don't_ have a "plan" file. I tried the "comp" command with some switches but all that would tell me is that the files are different sizes...no s**t, Einstein! *********** Another approach that might work is if there's a way to count how many times a folder name appears in the "dir /s /b" list. Customers without plans would appear only once. I don't know the syntax for "if" statements but maybe something like (and don't laugh)... if count of (foldernames) = 1 then (foldername) > cust_delete.txt ...if that makes any sense. But, then again the trick is pulling the folder name out of the entire string. Can I tell the program to read the lines up to the third "\". That could pull out C:\Customer_Files\Jones_Bob------05739\
Report Offensive Follow Up For Removal
|
|
Response Number 9
|
Name: dtech10
Date: January 5, 2004 at 14:29:02 Pacific
Subject: DOS batch file for deleting folders |
Reply: (edit)Hi Teasman This is the syntax for the find command. --------------- Searches for a text string in a file or files. FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]] /V Displays all lines NOT containing the specified string. /C Displays only the count of lines containing the string. /N Displays line numbers with the displayed lines. /I Ignores the case of characters when searching for the string. /OFF[LINE] Do not skip files with offline attribute set. "string" Specifies the text string to find. [drive:][path]filename Specifies a file or files to search. If a path is not specified, FIND searches the text typed at the prompt or piped from another command. ---------------- Sorry about the Deltree command, it's not installed with WinXP Pro. I am also using WinXP Pro I could send it to you, it's works ok with my system. Drop me a line a harryann@beeb.net and I'll sent you the version I'm using.
Report Offensive Follow Up For Removal
|

|

|
Use following form to reply to current message:
|
|

|