Windows batch file help

Dec 25, 2022 Last reply: 3 years ago 12 Replies

Given a folder C:\Protos, I want a batch file to find all sub-folders, possibly a few levels deep, called OLD, and delete all of them. I can't make that work.



When we develop a prototype PCB, we name iterations board1, board2, etc, and drag the old ones into an OLD folder until it's done. Spice folders get a OLD sub-folder too.



Windows batch files don't make a lot of sense to me. Too many ambiguities.



For example,



C:\Protos\Z540_P940_Load_Board\PCB\OLD



is full of obsolete iterations.



I'm afraid to delete old versions, because sometimes I need to go back and recover some lost item, or recover from a edit fumble. So I collect all such in a process archive of some kind, and keep it forever.

Joe Gwinn

It gets clunky, but not impossible. You could do a 'find' and redirect that output to a text file, the call another bat file to use the find results to delete. Powershell may have something smoother.

Cheers

Download XYplorer, it can find and list named files or directories starting from any location. It is one of the alternative to the standard windows file manager, and I would think most of the others also have this capability.

søndag den 25. december 2022 kl. 17.04.20 UTC+1 skrev John Larkin:

formatting link
?

Yikes. Maybe I'll just have someone do it.

I could write a PowerBasic program, I guess.

start with this to get the list of dirs to delete

cd c:\Protos

dir /AD OLD /s /B

you may need a lowercase b, you never mentioned what version of windows you're running.

Probably 3.0. He wants to upgrade to 3.1 to use USB, but can't find a Floppy drive that's not USB. lol

ITYM

dir /ad .\old /s /b >badbatch.txt

Otherwise it will falsely match things like bold cold fold folder told I think my search pattern is safe buit may still catch things you don't want to be zapped so double check its output!

Then edlin badbatch.txt

r/C:/del C:/ w q

I'd check it out manually first - my edlin is a little rusty. (and I bet edlin won't run on modern Windoze PCs)

It is basically just to tack "del " on the front of each line.

John Larkin snipped-for-privacy@highlandSNIPMEtechnology.com wrote in news: snipped-for-privacy@4ax.com:

Windows 10 allows one to have a Linux session within windows. Linux batch scripting is far more advanced.

It might not like the NTFS thing though.

You could use it to establish a list, which a Windows Power Shell batch file then uses for the deletion task.

mandag den 26. december 2022 kl. 19.39.18 UTC+1 skrev snipped-for-privacy@decadence.org:

WSL is fully integrated with windows, just cd to \mnt\c in linux

maybe use a port of GNU find.

formatting link
"C:\path_to\find.exe C:\Protos -name OLD -type d -delete"

Use Total Commander. To a "Search", feed the results back to the active window, Delete

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required