Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

Batch File: CALL SET ...

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
ReneGe
Asked:
ReneGe
  • 7
  • 6
  • 3
  • +1
2 Solutions
 
HainKurtSr. System AnalystCommented:
try

CALL SET File1=%File2:\Backup=%
0
 
HainKurtSr. System AnalystCommented:
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
 
ReneGeAuthor Commented:
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 Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ReneGeAuthor Commented:
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
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
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
 
HainKurtSr. System AnalystCommented:
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
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
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
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
sorry I left a trailing slash on the C:\

RoboCopy "E:\Backup" "C:" * /ZB /E
0
 
ReneGeAuthor Commented:
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
 
Bill PrewCommented:
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
 
ReneGeAuthor Commented:
Hey billprew !

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

Thanks again & Cheers,
Rene
0
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
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
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Glad I could help ReneGe! =)
0
 
ReneGeAuthor Commented:
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
 
Bill PrewCommented:
Bonus points for QCubed, woo hoo.

~bp
0
 
ReneGeAuthor Commented:
lol
0
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
lololol
0
 
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
working on that expert raking ^^
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 6
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now