Computer Hope

Microsoft => Microsoft DOS => Topic started by: dbam on March 04, 2008, 08:26:52 PM

Title: dir piped to move command failure [solved]
Post by: dbam on March 04, 2008, 08:26:52 PM
A command window in WinXP Pro given the instructions:

dir D:\*somestring* /S | move C:\somedirectory

What would happen to the files found by dir in the D drive?

The idea was to find all files in D with "somestring" in the name and move them all collectively to the directory in C drive. The result was that the directory in C vanished (complete with all contents) to never-neverland. So, obviously this was not the correct way to pipe the results of the search to the move command.

What would be the right way?

Title: Re: dir piped to move command failure
Post by: GuruGary on March 04, 2008, 10:04:09 PM
It sounds like what you need is actually something like this in a batch file:
Code: [Select]
for /f "tokens=*" %%a in ('dir D:\*somestring* /s /b') do move "%%a" C:\somedirectoryfor the same command directly in a command prompt, change the %%a to just %a
Title: Re: dir piped to move command failure
Post by: dbam on March 04, 2008, 10:24:23 PM
Quote
for the same command directly in a command prompt, change the %%a to just %a
Thanks for the reply.
What are the percent signs telling the program to do?
Also, any idea what the command I used did with the directory that vanished? Is it forever gone?
Title: Re: dir piped to move command failure
Post by: Dias de verano on March 04, 2008, 11:47:16 PM
What are the percent signs telling the program to do?

To create and use variables.

Title: Re: dir piped to move command failure
Post by: dbam on March 05, 2008, 10:58:56 AM
Quote
A command window in WinXP Pro given the instructions:

Code: [Select]
dir D:\*somestring* /S | move C:\somedirectory
Quote
What would happen to the files found by dir in the D drive?

Alas, it moved "C:\somedirectory into my home directory lock, stock and barrel, complete with the *somestring* files that it found. My guess is that it didn't know where else to put it since I didn't specify.

Thanks Gary and Dias for the pointers and good help.