Solved

Batch File: CALL SET ...

Posted on 2010-08-16
18
405 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 53

Expert Comment

by:Huseyin KAHRAMAN
ID: 33446661
try

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

Expert Comment

by:Huseyin KAHRAMAN
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Assisted Solution

by:Huseyin KAHRAMAN
Huseyin KAHRAMAN 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 12

Accepted Solution

by:
Ben Personick (Previously QCubed) 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 12
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 54

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 12
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 12
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 54

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 12
ID: 33448984
lololol
0
 
LVL 12
ID: 33448987
working on that expert raking ^^
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

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.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

752 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