?
Solved

Batch File: CALL SET ...

Posted on 2010-08-16
18
Medium Priority
?
409 Views
Last Modified: 2012-05-10
Hi there,

Now it's time for me to get familiar with the command line CALL SET ...


SCRIPT TO COMPLETE:
-------------------------------------
@echo off
SET BasePath=C:\Documents
SET BackupPath=E:\Backup
SET File2=E:\Backup\Documents\whatever.txt

CALL SET File1=[Remove BackupPath from File2 and add BasePath's full path to File2.]
ECHO %File1%
ECHO.
PAUSE
EXIT


EXPECTED RESULT:
----------------------------
C:\Documents\whatever.txt




SCRIPT TO COMPLETE & WITHIN A FOR COMMAND:
-----------------------------------------
@echo off
setlocal enabledelayedexpansion

SET BasePath1=C:\Documents
SET BasePath2=C:\HerDocuments
SET BackupPath=E:\Backup
SET File1=E:\Backup\HerDocuments\whatever.txt
SET File2=E:\Backup\Documents\whatever.txt

FOR /L %%A IN (1,1,2) do (
  CALL SET File%%A=[Remove BackupPath from File%%A and add BasePath's full path to File%%A.]
  ECHO !File%%A!
  )
ECHO.
PAUSE
EXIT


EXPECTED RESULT:
----------------------------
C:\HerDocuments\whatever.txt
C:\Documents\whatever.txt




Thanks,
Rene
0
Comment
Question by:ReneGe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 3
  • +1
18 Comments
 
LVL 59

Expert Comment

by:HainKurt
ID: 33446661
try

CALL SET File1=%File2:\Backup=%
0
 
LVL 59

Expert Comment

by:HainKurt
ID: 33446691
based on my previous post, you can find the solution for your other problem I guess...

if above does not work, try to run cmd with /v: "cmd /v:ON"
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33446726
HainKurt,

Here is the output I got:
E:\Documents\whatever.txt

I dont get what you mean with [cmd /v:ON"]

Thanks for helping,
Rene
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Author Comment

by:ReneGe
ID: 33446980
Ok, I now understand  [cmd /v:ON"]

In the first script, I dont use a FOR command thefore, dont need to enable delayed environment variable expansion.

However, in the second script, you will find [setlocal enabledelayedexpansion], which does it.

Thanks again for helping,
Rene
0
 
LVL 14
ID: 33447152
CALL SET  File2=%BasePath%%%File2:%BackupPath%=%% will work
CALL SET  File2=%%File2:%BackupPath%=%BasePath%%% also may work...

NOTE: you cannot use a FOR variable as a variable within a variable even in a SET command
0
 
LVL 59

Assisted Solution

by:HainKurt
HainKurt earned 800 total points
ID: 33447295
what about this one

(i changed your BackupPath)
@echo off
SET BasePath=C:\Documents
SET BackupPath=E:\Backup\Documents
SET File2=E:\Backup\Documents\whatever.txt

CALL SET File1=%BasePath%!File2:%BackupPath%=!
ECHO %File1%
...

Open in new window

0
 
LVL 14

Accepted Solution

by:
Ben Personick (Previously QCubed) earned 1200 total points
ID: 33447305
I see you are trying to add the value of the %%A to be between the start and finish, why not just do this??

CALL SET File2=C:\%%File2:%BackupPath%=%%

Better yet why not just use Robocopy like this:
RoboCopy "E:\Backup" "C:\" * /ZB /E
0
 
LVL 14
ID: 33447309
sorry I left a trailing slash on the C:\

RoboCopy "E:\Backup" "C:" * /ZB /E
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33447700
Hey QCubed!

==> HainKurt
Following your script, here is the output:
C:\Documents!File2:E:\Backup\Documents=! SET.txt

==> QCubed, I got
Following your script, here is the output:
C:\Documents\whatever.txt

Thanks for the Robocopy command line.  However, my focus here is to get familiar with "Call Get..."

QCubeb line also works with the script containing the FOR command:

@echo off
setlocal enabledelayedexpansion

SET BasePath1=C:\Documents
SET BasePath2=C:\HerDocuments
SET BackupPath=E:\Backup
SET File1=E:\Backup\HerDocuments\whatever.txt
SET File2=E:\Backup\Documents\whatever.txt

FOR /L %%A IN (1,1,2) do (
  CALL SET File%%A=C:%%File%%A:%BackupPath%=%%
  ECHO !File%%A!
  )
ECHO.
PAUSE
EXIT

I must see working practical examples to understand concepts.  Thanks for helping me understanding the "CALL SET..." command.

Cheers,
Rene
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 33447748
Just want to make sure you didn't miss it, this was accomplished in my last post to a prior thread, at:

http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_26399261.html#a33434946

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33447885
Hey billprew !

Thanks for insisting. I in deed, missed your [CALL SET SourceFileFull=%%DestFileFull:...] line

Thanks again & Cheers,
Rene
0
 
LVL 14
ID: 33448228
lol, BP.  I thougth about linking him back to my comment in thaat chain too where I explained it as well:

http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_26399261.html#a33426027


08/12/10 08:48 PM, ID: 33426027


0
 
LVL 14
ID: 33448244
Glad I could help ReneGe! =)
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33448330
Sorry guys, the thing is that seeing CALL & ECHO in the same line was for me blinded by the paradigme of the way I'm use to see them. I just did not see it until you put a focus on it.

Cheers,
Rene
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 33448840
Bonus points for QCubed, woo hoo.

~bp
0
 
LVL 10

Author Comment

by:ReneGe
ID: 33448981
lol
0
 
LVL 14
ID: 33448984
lololol
0
 
LVL 14
ID: 33448987
working on that expert raking ^^
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Progress

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question