|
Answer» Hi,
my batch file schould remove all from "my_dir" but not "my_dir". There are directories in "my_dir". They schould be also removed. I've tried this with rmdir /s/q my_dir/., but I get an error: Invalid SWITCH - ".". How can I do this without rmdir my_dir mkdir my_dir?
Thanks beforehand, regards, sipungora.As far as I am aware the rmdir only deletes empty directories.
You would have to use deltree command which would delete everything contained with that directory.There is no deltree for Windows XP, only rmdir . I dislike writing destructive code for other users. Backup the my_dir before proceeding.
Code: [Select]@echo off for /f "TOKENS=* delims=" %%v in ('dir /s /b /a:-d my_dir') do ( echo del /f %%v ) for /f "tokens=* delims=" %%v in ('dir /s /b /a:d my_dir') do ( echo rd /s /q %%v )
The code above will display what is to be deleted. When you are satisfied, remove the word echo from within each for loop.
The quick way would be to remove my_dir and immediately re-create it.Unfortunately after echo removing nothing was removed from my_dir.
The case remove my_dir and re-create my_dir is ALREADY in use. But this is not so COMFORTABLE. If I'm observing content of my_dir through the "Windows Explorer", after remove my_dir "Windows Explorer" will be always closed and I have to open it again to further observation or I must always go into the parent directory in Windows Explorer, before my_dir will be removed. have you tried del/?
FbCode: [Select]@echo off for /f "tokens=* delims=" %%v in ('dir /s /b /a:-d my_dir') do ( del /f %%v ) for /f "tokens=* delims=" %%v in ('dir /s /b /a:d my_dir') do ( rd /s /q %%v )
Warning: The above code is destructive and will delete files and directories.
Quote The case remove my_dir and re-create my_dir is already in use. But this is not so comfortable. If I'm observing content of my_dir through the "Windows Explorer", after remove my_dir "Windows Explorer" will be always closed and I have to open it again to further observation or I must always go into the parent directory in Windows Explorer, before my_dir will be removed.
If you are trying to remove files/directories why are you accessing the directory in explorer? As long as you're in explorer, why not do the deletions there? It would be a lot safer as explorer can send files/directories to the recycle bin whereas batch scripts do not.
Because in batch file I can INSERT several commands and with Windows Explorer I can only do one thing at the same time.
|