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
Solved

FOR command and SET command in a batch file

Posted on 2008-06-26
4
291 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 84

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

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...
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
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…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

856 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