Using xcopy or copy for a single file from multiple folders -


so in batch script i'm building taking single file folder, copying on destination folder, , renaming based on number of times script has been looped. need take file that's named samething bunch of different folders spread across multiple computers @ times , copy them new folder work with. i've read on xcopy , copy seemed thing use haven't been able find lets me tell copy on single named file. i've posted have far script below commented lines sections haven't figured out:

echo off setlocal enabledelayedexpansion  echo note: combined permission list cvs can found in desktop folder  set /a #=-1 :start  set /a #+=1  :again     echo please input file path permissionoutput.txt set /p permissionoutputpath=  set "sourcefolder=%permissionoutputpath%" set "destinationfolder=c:\users\kayla\desktop\holder-combinedpermissionslists" if not exist "%sourcefolder%\permissionoutput.txt" echo file not found&goto again copy "%sourcefolder%\permissionoutput.txt" "%destinationfolder%\permissionoutput%#%.txt"  echo add file combine: y or n? set /p addanotherfile= if %addanotherfile%==y goto :start 

update: code corrected answer functional use reference

set /a #=-1 :start  set /a #+=1  :again     echo please input file path permissionoutput.txt set /p permissionoutputpath=  set "sourcefolder=%permissionoutputpath%" set "destinationfolder=c:\users\kayla\desktop\holder-combinedpermissionslists" if not exist "%sourcefolder%\permissionoutput.txt" echo file not found&goto again copy "%sourcefolder%\permissionoutput.txt" "%destinationfolder%\permissionoutput%#%.txt"  echo add file combine: y or n? set /p addanotherfile= if /i "%addanotherfile%"=="y" goto start 

# legitimate variable-name. it's initialised -1 incremented on each loop through :start first value have when it's used 0. (if want start @ 1 initialise 0 instead)

next - sets - but spaces significant in string set command included in variablename/value assigned if present in set instruction. "quoting assignment" ensures stray trailing spaces on line not included in value assigned.

well - next, make sure file exists , if doesn't, produce message , loop :again bypasses increment of #.

otherwise, copy file. you're aware of sourcename, , destinationname constructed including %#% include current value of # (all batch variables without exception strings - set /a instruction merely converts string binary perform required calculation, converts result string storage in environment.)

finally, interpreting request add file. if /i makes comparison case-insensitive. since have no direct control on user's response, "quoting each side" ensures if syntax isn't violated in case user enters "yup sure 'nuff" or other unexpected response.

the leading colon not required in goto. prefer omit keep conguity call command no-colon means external routine called , colon means routine in batch file.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -