Solved

FOR command and SET command in a batch file

Posted on 2008-06-26
4
266 Views
Last Modified: 2010-04-21
I have the copy part working due to an answer in a previous question
FOR %%A IN (%*) DO (
       rem copy the file
      COPY %%A "%temp%\~1234WSS4321\%%~nxA"
      SET X=%X% %%~nxA
)

the set part does not work.... why?  How can I do it.
I need the environment variable to =
filename1.tif filename2.tif filenamex.tif
0
Comment
Question by:SStory
  • 3
4 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 21877809
Now I get it, I think; you want to "collect" the file names in the variable "X"?
Then you're currently fighting with the fact that the interpreter is expanding regular variables only once when the line is read; enter "help set" for details, look for the "delayed expansion".
To fix this, use this:

setlocal enabledelayedexpansion

FOR %%A IN (%*) DO (

       rem copy the file

      COPY %%A "%temp%\~1234WSS4321\%%~nxA"

      SET X=!X! %%~nxA

)

Open in new window

0
 
LVL 25

Author Comment

by:SStory
ID: 21878559
You're right about what I want to do, but it didn't work.
I am getting:
'~nxA' is not recognized as an internal or external command,
operable program or batch file.
You have made my day! 

You are definitely Mr. Batch Expert in my book.

I looked through a lot of docs and help and COULD not figure out what to do!
 

Thanks a bunch.

Now with this batch file and some free tools from TiffLib I can let my users take multiple TIFF files and convert them to one PDF, at no cost!!!

Open in new window

0
 
LVL 25

Author Comment

by:SStory
ID: 21878564
Oops... Sorry.. At first I thought it wasn't work. I had && instead of %%
Disreguard the comment in the above and read the code snippet..
I goofed.

Thanks.
0
 
LVL 25

Author Closing Comment

by:SStory
ID: 31471114
Awesome! You have made my day!  I looked at lots of docs and help but just
couldn't get it. Now my TIFFS to PDF will work for users in a simple way.

Thanks again!
0

Featured Post

The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

Join & Write a Comment

Suggested Solutions

The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

746 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

11 Experts available now in Live!

Get 1:1 Help Now