Solved

Batch File: CALL SET ...

Posted on 2010-08-16
18
398 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
  • 7
  • 6
  • 3
  • +1
18 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 33446661
try

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

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
 
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 11

Expert Comment

by:Ben Personick
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 51

Assisted Solution

by:HainKurt
HainKurt earned 200 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 11

Accepted Solution

by:
Ben Personick earned 300 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 11

Expert Comment

by:Ben Personick
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 52

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 11

Expert Comment

by:Ben Personick
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 11

Expert Comment

by:Ben Personick
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 52

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 11

Expert Comment

by:Ben Personick
ID: 33448984
lololol
0
 
LVL 11

Expert Comment

by:Ben Personick
ID: 33448987
working on that expert raking ^^
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now