DOS Command Continue on Next Line

jstevens
SilverLounger
Posts: 2497
Joined: 26 Jan 2010, 16:31
Location: Southern California

DOS Command Continue on Next Line

I utilize this bit of code to copy files from source to a target destination and it works quite nicely.

Code: Select all

                  FOR /f "tokens=*" %%G in ('dir /a /b %Source%%File%') Do (echo F| xCopy /H/Y %Source%%%G "%Destination%Copy of %%G" & attrib -h "%Destination%Copy of %%G")                                  

What I would like to do is wrap some of the code to a new line such as:

Code: Select all

                  FOR /f "tokens=*" %%G in ('dir /a /b %Source%%File%')^       Do (echo F| xCopy /H/Y %Source%%%G "%Destination%Copy of %%G" & attrib -h "%Destination%Copy of %%G")                                  

Unfortunately the code fails to run by entering a "^" as the line seperator.

Your suggestions are appreciated,
John

Regards,
John


jstevens
SilverLounger
Posts: 2497
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: DOS Command Continue on Next Line

Post by jstevens »

I found a solution by placing the "^" here:

Code: Select all

                  FOR /f "tokens=*" %%G in ('dir /a /b %Source%%File%') Do (^         echo F| xCopy /H/Y %Source%%%G "%Destination%Copy of %%G" & attrib -h "%Destination%Copy of %%G")                                  

Regards,
John

Regards,
John



User avatar

John Gray
PlatinumLounger
Posts: 5197
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: DOS Command Continue on Next Line

Post by John Gray »

You don't even need the ^ in that circumstance!

A 'live' example fragment:

Code: Select all

                  :: get the current hours/minutes/seconds/centiseconds (since midnight) for /f "tokens=5-8 delims=:,. " %%a in ('echo:^|time') do (   set /a hh=%%a,mm=1%%b-100,ss=1%%c-100,cc=1%%d-100 )                                  

John Gray

I thought Ariana Grande was a font...


jstevens
SilverLounger
Posts: 2497
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: DOS Command Continue on Next Line

Post by jstevens »

John,

One additional thought I had is to search the file for certain text and if found perform the copy.

Such as:

Code: Select all

                  FOR /f "tokens=*" %%G in ('dir /a /b %Source%%File%') Do ( 	 	Find "ADJ" %%G | find ": 0" 1>nul %% echo F| xCopy /H/Y %Source%%%G "%Destination%Copy of %%G" & attrib -h "%Destination%Copy of %%G"  )                

I painted myself into a corner,
John

Regards,
John


User avatar

John Gray
PlatinumLounger
Posts: 5197
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: DOS Command Continue on Next Line

Post by John Gray »

When you paint yourself into a corner, you need to stand back and see if you can do things in a more straightforward way.
For example, I suspect that you would need to put a pair of brackets after the && (not %%, typo!) and after the attrib statement.
And I would use Robocopy rather than Xcopy - needs a bit of learning, but more reliable.

Code: Select all

                  FOR /f "tokens=*" %%G in ('dir /a /b %Source%%File%') Do (      Find "ADJ" %%G | find ": 0" 1>nul && (     echo F| xCopy /H/Y %Source%%%G "%Destination%Copy of %%G" & attrib -h "%Destination%Copy of %%G"   ) )                                  

See if that works!

John Gray

I thought Ariana Grande was a font...


jstevens
SilverLounger
Posts: 2497
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: DOS Command Continue on Next Line

Post by jstevens »

John,

It did not work. The error message being returned is "file not found".

It would appear the "find" is the culprit. I modified it slightly to determine what if anything was wrong. If ADJ is found in the filename then echo the filename.

Code: Select all

                                      Find "ADJ" %%G | find ": 0" 1>nul && echo %%G                

Regards,
John

Regards,
John


User avatar

John Gray
PlatinumLounger
Posts: 5197
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: DOS Command Continue on Next Line

Post by John Gray »

Of course I don't have access to your files!
It may be worth having a read through the help information for both FIND and FINDSTR, because sometimes the one is better than the other for what is wanted.

John Gray

I thought Ariana Grande was a font...


jstevens
SilverLounger
Posts: 2497
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: DOS Command Continue on Next Line

Post by jstevens »

John,

The Find command look at the contents of the file and returns those lines which meet the criteria "ADJ". This is not what I would like to do.

I am recursing through a directory looking at file names. If a file name contains "ADJ" then I would like to copy the file to the target path. If it does not contain "ADJ" then do nothing.

Regards,
John

Regards,
John