|
Answer» I am TRYING to create a dos batch FILE in Version 5.1.2600 to do the following.
My file structure is like this...
c:\Program Files\AR System\HOME6
I want to delete all files/folders under HOME6 except for files with extensions *.iniI only have files with .ini extensions that I do not want to delete. Where do I add the paths? Is it after 'dir..?Code: [Select] @echo off for /f %%a in ('dir /b "c:\Program Files\AR System\HOME6\*.*"') do (if not %%~xa==.ini del "c:\Program Files\AR System\HOME6\%%a")
It's pretty much like you thought. Good luck. This works nicely however one last thing. Now that the files are deleted, is it possible to also delete the directory under HOME6? c: \Program Files \AR System \HOME6 \FOCxC001 \FOCxGrou \FOCxJOIN \FOCxSLAx
After I run the above command the 4 directories under HOME6 are now empty and I would like to delete them. There could hundreads of directories to delete...
tksIf I understand this correctly, you've deleted the files (except for .ini files) from the Home6 directory. Now you want to delete all the subfolders from Home6?
This shoud HELP you out:
Code: [Select] for /d %%a in ('dir /b "c:\Program Files\AR System\HOME6\*.*"') do rd /s /q %%a
RD with the /s switch is very DESTRUCTIVE. All files in the subfolders will be deleted along with the parent directory.
Use CAUTION.
Hope this helps.
The RD command has been very popular this week. Maybe we should run a special like the FOR special we had a few weeks ago.So now my batch file looks like this...
@echo off for /f %%a in ('dir /b "c:\Program Files\AR System\HOME6\*.*"') do (if not %%~xa==.ini del "c:\Program Files\AR System\HOME6\%%a") for /d %%a in ('dir /b "c:\Program Files\AR System\HOME6\*.*"') do rd /s /q %%a
Is this good? When I run it, I always get prompted "Are you Sure?" Can this be removed? Also, it still does not remove the directories.
tksI probably should have READ some of Sidewinder's old posts. I guess some days are better than others.
This should work:
Code: [Select] @echo off for /f %%a in ('dir /b "c:\Program Files\AR System\HOME6\*.*"') do (if not %%~xa==.ini del "c:\Program Files\AR System\HOME6\%%a") for /d %%a in ("c:\Program Files\AR System\HOME6\*") do echo %%a
The above code will list the directories to be deleted. When you are satisfied everything is cool, replace echo with rd /s /q
The /q switch when used with the /s switch is supposed to eliminate the "Are You Sure?" prompt. I can't explain why it doesn't work on your machine.
Standard disclaimer: File and directories deleted thru scripts do not make a pit stop in the recycle bin on their way to dataland. Plan accordingly.
Good luck.
|