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
how to delete
Moderator: DosItHelp
-
- Posts: 84
- Joined: 08 Sep 2010 10:25
- Location: Iran,Kashan
- Contact:
Re: how to delete
DEL deletes files, RD (or RMDIR) removes folders.
As one-liner.
But normally I would write a block (for a better readability).
Regards
aGerman
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
-
- Posts: 84
- Joined: 08 Sep 2010 10:25
- Location: Iran,Kashan
- Contact:
Re: how to delete
do u can explain that?
please teach "for" command in a new topic for us.
thank u
please teach "for" command in a new topic for us.
thank u
-
- Posts: 79
- Joined: 13 Dec 2010 10:32
Re: how to delete
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:
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.
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"