1.

Solve : Piping Question ...?

Answer»

Hello all,

Could anyone please shed some light as to why none of the following work (xp prompt), its fairly obvious what I am trying to achieve ...

rd/s/q *

rd/s/q < listOfDirs

dir/b/ad | rd/s/q

Been winding me up all day ... thanks,

BoByes its obvious. but show the error messages you got...if anywhat an incredibly helpful reply !

whats so obvious about it? when your carrying out the first command in a directory that only contains other directories (no files), the second command TRIES to get its input from listOfDirs which is the output of a dir/b/ad > listOfDirs.

Anyway, for the first one I get :

The filename, directory name, or volume label syntax is incorrect.

And for the second + third ones I get :

The syntax of the command is incorrect.I don't know your intentions, but they can't be good...

Though, for the first one, try:

Code: (Delete all files/folders in the current dir, inc.) [Select]rd /s /q %cd%I have a hard drive that needs wiping and wanted to do it in dos ... ?

Thank you so much for your answer tho 'DeltaSlaya', have learned from that!

Could anyone tell me the reason for the piping / redirecting not working however?WELL you said:

Quote

Could anyone please shed some light as to why none of the following work (xp prompt), its fairly obvious what I am trying to achieve ...

So, I assumed wrong.

But, to answer your question.

Quote from: RD Help
C:\>rd /?
Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

/S Removes all directories and files in the specified directory
in addition to the directory itself. Used to remove a directory
tree.

/Q Quiet MODE, do not ask if ok to remove a directory tree with /S

Note the singluar 'directory' etc.
This means that piping or by other means giving a list of directories to the rd command will NOT work. It requires a directory name.

Also, if you want * a wildcard to work I think you have to use the 'del' command.

Code: (this would grab a directory name from a file and use it) [Select]@set dirname=<dirtodelete.txt
@rd /s /q %dirname%
NOTE: That will only work for one directory in the file. Pretty pointless but it wouldn't work the other way.Thank you again DeltaSlaya ... however, what I dont understand is that if rd is only supposed to work with a single directory, then why does this code work as expected ...

md moo cow duck
rd moo cow duck

You see what I mean?Good point. Looking over it again i see how that could work. But the two original methods you supplied will not work. Perhaps a for statement could perform it with multiple directories as well.

To use a file with a list of directories on each line, or on the same with a space on each this should work.

Code: [Select]for /F "delims=" %%i in ('findstr . dirstodel.txt') do rd /s /q %%i
I'm learning for statements myself, but that should work with a file full of directories.This may explain better, but remember I'm not a DOS command expert:

Code: [Select]@echo off

:: Create txt file with list of dirs
echo Testfolder1 Testfolder2 Testfolder3 Testfolder4 Testfolder5>todel.txt

:: Assign var with contents
set /p d=<todel.txt

:: Make directories
mkdir %d%

:: So you can check they were made
echo Any key.
pause >nul

:: Delete with FOR
for /F "delims=" %%i in ('findstr . todel.txt') do rd /s /q %%i

::Finished
echo.
echo Done.
ping -n 3 LOCALHOST >nulOk I will look over that! Thanks for your help! TOP man!


Discussion

No Comment Found