Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append a string in Bat file

Status
Not open for further replies.

Milleniumlegend

IS-IT--Management
Dec 16, 2003
135
I have a Variable that I would like to append with dynamic values.

I am trying the following

Code:
SET SRCSHORTCUTS="F:\BATCH\shortcuts\"
SET DESTSHORTCUTS="F:\Temp\shortcuts"

XCOPY %SRCSHORTCUTS% %DESTSHORTCUTS%

There is another folder under SRCSHORTCUTS called t1 or t2 or t3 etc. depending on the input we get from the user say from 1 to 5 or p or u.

So I was trying something like

Code:
%input% (could be 1 or 2 or 3 or 4 or 5 or p or u)
XCOPY %SRCSHORTCUTS%t%input% %DESTSHORTCUTS%

the above String append gives me an error. Could someone please let me know how can I achieve this.
 
When using the command
dir %SRCSHORTCUTS% /ad /b
you get a list of all the folders in your %SRCSHORTCUTS%
You can redirect this to a temporary file,
dir %SRCSHORTCUTS% /ad /b >folderlist.txt

Now you are able to process this list with a FOR loop.
Use help FOR on your CommandPrompt to find out the syntax that best fits your needs.

When more folders exist in the %SRCSHORTCUTS% folder you might use the command
dir %SRCSHORTCUTS% /ad /b | find /i " t" >folderlist.txt
This will produce a list with all folders beginning with a 't' or a 'T' in your %SRCSHORTCUTS%
 
How about

XCOPY %SRCSHORTCUTS%t%input%\*.* %DESTSHORTCUTS%

i.e. add a backslash & filespec after the source to indicate entire folder contents. Works for me.

Jock
 
I usually use copy. Put the text you want to append to the batch file into a text file, and add it in copy like this:

copy batch.bat+added.txt batch.bat

 
set /p input= Enter 1,2,3,4,5,p, or u

This will set %input% to what the user enters.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top