Page 1 of 1
how to delete
Posted: 07 Jan 2011 02:50
by Mohammad_Dos
Hi,
I want delete all files and directories there is in c:\a
but I dont want delete this folder and just delete files and folders in it.
how?
(by one line. if it is possible)
thank u
Re: how to delete
Posted: 07 Jan 2011 14:14
by aGerman
DEL deletes files, RD (or RMDIR) removes folders.
As one-liner.
Code: Select all
pushd "C:\a"&&(del /f /q /a *&(for /f "delims=" %%a in ('dir /ad /b') do rd /s /q "%%~a")&popd)
But normally I would write a block (for a better readability).
Code: Select all
pushd "C:\a" &&(
del /f /q /a *
for /f "delims=" %%a in ('dir /ad /b') do rd /s /q "%%~a"
popd
)
Regards
aGerman
Re: how to delete
Posted: 12 Jan 2011 04:33
by Mohammad_Dos
do u can explain that?
please teach "for" command in a new topic for us.
thank u
Re: how to delete
Posted: 12 Jan 2011 07:26
by ChickenSoup
For is a loop.
See: FOR /?
"For /f" will parse each line of a file and will output the line as a single variable or variable set depending on the delimiters used.
So, the For loop will process each line of 'dir /ad /b'. If this was run against the C: drive, you would get an output something like this as the dir command:
Code: Select all
Documents and Settings
Program Files
RECYCLER
System Volume Information
WINDOWS
Your for loop would then process each line of the above output into whatever is after your 'do' statedment. In this case it would try to do the following.
Code: Select all
rd /s /q "Documents and Settings"
rd /s /q "Program Files"
rd /s /q "RECYCLER"
rd /s /q "System Volume Information"
rd /s /q "WINDOWS"