Solved

FOR command and SET command in a batch file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

929 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