|
|
Question : Trying to delete certain folders on startup.
|
|
I'm trying to write a DOS batch script that will run under XP's cmd shell to take the names of any folder that starts with a dollar sign and delete the folder. I'd like to use deltree, but they don't support that anymore. I have it where I can export the folder names using DIR to an Excel spreadsheet automatically, with the full folder paths in one cell each in the first column. I have found an Excel macro utility that can export the paths to a text file, but only if the spreadsheet I wrote the paths to using DOS is open and the paths I want deleted are highlighted manually in the sheet and I hit Ctrl+Shift+W after highlighting. Once in a text file, I would want the names able to be controlled as variables so I can call the folder paths up, delete their contents with a *.*, and then cd.. and rmdir %folderpath%. If someone knows a better way to do this, then please share. Otherwise, if I can just get the text in my text file into a variable, I can probably get it from there. Set pathway=C:\list.txt does not work (the pathway variable will equal "C:\list.txt", not the content within list.txt) and neither does list.txt | %pathway% or list.txt > %pathway%. Something similar to that, though.... After that I can put the .bat file in the startup directory. Please help.
|
Answer : Trying to delete certain folders on startup.
|
|
This should do the trick:
@echo off
pushd.
cd /d c:\temp
for /f "delims=" %%a in ('dir /b /ad $* 2^>NUL') do echo rd "%%a" /s /q
popd.
Note, I've put an echo statement prior to the rd (remove directory) command for testing. To enable remove the echo statement.
|
|
|
|
|