Hi All,
I have a log listing fully qualified file names that need to be copied.
ie.
\\some.server.domain.ca\c$\storage\folder\with\stuff\init.jpg
\\some.server.domain.ca\c$\storage\folder\with\stuff\more.jpg
\\some.server.domain.ca\c$\storage\folder\with\stuff\again.tif
the bit of code I'm fighting with is this
setlocal enabledelayedexpansion
(for /f "tokens=*" %%a in (!dest2!output.log) do (
set filenames=%%a
set spath=!filenames:~73,0!
xcopy !filenames! !dest2!!spath! /f /h
))
it should, take the fully qualified names and load them into !filenames! to be the source for xcopy, and also remove 73 characters from the front of each line, so xcopy can create the same directory structure in the destination. (those 73 characters are \\some.server..... which i don't need. )
I can't tell if anything is being loaded into !spath! the echo output just shows !spath! rather than the data (if any) in it.
- Kip
Remove leading characters and pass to new variable
Moderator: DosItHelp
-
- Posts: 79
- Joined: 13 Dec 2010 10:32
Re: Remove leading characters and pass to new variable
You can remove the "\\some.server..." with a better use of for and not be bound to a certain number of characters like below.
will give you:
--or--
will give you:
You should be able to use the value of %%b to get your desired results in the xcopy and then drop the SET statements.
Code: Select all
for /f "tokens=1* delims=\" %%a in (output.log) do echo %%b
will give you:
c$\storage\folder\with\stuff\init.jpg
c$\storage\folder\with\stuff\more.jpg
c$\storage\folder\with\stuff\again.tif
--or--
Code: Select all
for /f "tokens=2* delims=\" %%a in (output.log) do echo %%b
will give you:
storage\folder\with\stuff\init.jpg
storage\folder\with\stuff\more.jpg
storage\folder\with\stuff\again.tif
You should be able to use the value of %%b to get your desired results in the xcopy and then drop the SET statements.
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Re: Remove leading characters and pass to new variable
untested:
This part:
!filenames:~73,0!
will return 0 characters skipping the first 72 characters. I believe you want:
!filenames:~73!
Which just skips the first 72 characters and returns everything else.
This part:
!filenames:~73,0!
will return 0 characters skipping the first 72 characters. I believe you want:
!filenames:~73!
Which just skips the first 72 characters and returns everything else.
Re: Remove leading characters and pass to new variable
avery_larry wrote:untested:
This part:
!filenames:~73,0!
will return 0 characters skipping the first 72 characters. I believe you want:
!filenames:~73!
Which just skips the first 72 characters and returns everything else.
Thanks avery_larry!
I had just looked that function up, I've never used it before, so I'm not surprised I was using it wrong =)
- Kip
Re: Remove leading characters and pass to new variable
ChickenSoup wrote:You can remove the "\\some.server..." with a better use of for and not be bound to a certain number of characters like below.Code: Select all
for /f "tokens=1* delims=\" %%a in (output.log) do echo %%b
will give you:c$\storage\folder\with\stuff\init.jpg
c$\storage\folder\with\stuff\more.jpg
c$\storage\folder\with\stuff\again.tif
--or--Code: Select all
for /f "tokens=2* delims=\" %%a in (output.log) do echo %%b
will give you:storage\folder\with\stuff\init.jpg
storage\folder\with\stuff\more.jpg
storage\folder\with\stuff\again.tif
You should be able to use the value of %%b to get your desired results in the xcopy and then drop the SET statements.
Your right Chickensoup that would be a better way to go about it, and as avery_larry pointed out I was using :~72,-0 wrong anyway... thanks!