Batch file to copy multiple CSV files to one TXT file by setting (prompting) variable dates

时间:2016-10-20 12:35:46

标签: date csv batch-file copy

I am new to this site and have only a few experience in batch files. I have a folder full of CSV (daily report) and I want to ba able to export them to a TXT file. This I can do it using the "copy" command, but my problem is; I want the batch file to prompt for the "from-to" date... I don't want to modify the script every time I want to generate a TXT file for a specific range of consecutive date.

Can I use variable in the xopy /D:****** parameter?

So far, here is my tryout:

@echo off

set /p NAME="Enter the file name: " %=%
set /p YY ="Enter the year (YY): " %=%
set /p MM ="Enter the month (MM): " %=%
set /p DD ="Enter the day (DD): " %=%

net use r: /delete
net use g: /delete
net use s: /delete
net use h: /delete
net use t: /delete
net use i: /delete

net use r: \\192.168.1.51\hdd1\PastJobHistory 
net use g: \\192.168.1.253\util\cnc_1
xcopy r:\*.csv g:\ /D:%MM%-%DD%-%YY% /Y
copy g:\*.csv g:\%NAME%.txt /Y

net use s: \\192.168.1.52\hdd1\PastJobHistory
net use h: \\192.168.1.253\util\cnc_2
xcopy s:\*.csv h:\ /D:%MM%-%DD%-%YY% /Y
copy h:\*.csv h:\%NAME%.txt /Y

net use t: \\192.168.1.53\hdd1\PastJobHistory
net use i: \\192.168.1.253\util\cnc_3
xcopy t:\*.csv i:\ /D:%MM%-%DD%-%YY% /Y
copy i:\*.csv i:\%NAME%.txt /Y

net use r: /delete
net use g: /delete
net use s: /delete
net use h: /delete
net use t: /delete
net use i: /delete

Thanks all!

0 个答案:

没有答案