Solved

Batch File: CALL SET ...

Posted on 2010-08-16
18
399 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
DevOps Toolchain Recommendations

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

 
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
 
LVL 53

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 53

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.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

776 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