Windows: Copying files using wildcard directories

command-line-interfacewindows

We have a third party app that stores data to directories by date (and then by instance) and we want to copy the *.csv files from that directory to a server. We only want the data from the instance directories — nothing higher, nothing lower.

Example structure (ItemX is the instance and there can be child directories):

C:\APP
------ Machine1
------ -------- Data
------ -------- ---- 081209
------ -------- ---- ------ Item1 -> report.csv
------ -------- ---- ------ Item2 -> report.csv
------ -------- ---- 081109
------ -------- ---- ------ Item1 -> report.csv
------ -------- ---- ------ Item2 -> report.csv
------ Machine2
------ -------- Data
------ -------- ---- 081209
------ -------- ---- ------ Item1 -> report.csv
------ -------- ---- ------ Item2 -> report.csv
------ -------- ---- 081109
------ -------- ---- ------ Item1 -> report.csv
------ -------- ---- ------ Item2 -> report.csv

Is there a generic way to write this so that we can just create one script instead of one per machine?

Best Answer

If the machineX is the name of the machine you can use the environment variable %COMPUTERNAME%

something similar to

xcopy c:\app\%computername%\Data\*\Item?\*.csv target\* /s