Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

FOR command and SET command in a batch file

Posted on 2008-06-26
4
Medium Priority
?
313 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
[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
  • 3
4 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

598 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