user1044111
user1044111

Reputation: 57

Windows batch file to copy files allow for renamed file extension but not copy duplicates

I want to copy files from two directories on a remote computer to a single directory on a windows server. In one directory I have files with the extension *.csv and in the other *.asc. Drives have been mapped with the UNC convention so we have drives such as Z:\ which are mapped to a specific folder on another computer. The scripts can reside in either the remote computer or on the windows server.

The files with the *.asc extension are then processed and then need to be renamed or moved to another directory (which our software does). The files with the *.csv extension are not changed

I tried using Robocopy and this worked with the MOVE switch

c:\scripts\ROBOCOPY.exe z:\ C:\files\Magellan /MOV /NP /R:2 /W:2 *.asc >c:\scripts\synchro.log 

However, the source programme / software requires that these *.asc remain in the original source location - so I can`t use the move switch.

I don`t want to copy duplicate *.asc files - otherwise these files will be processed again.

So I need to only copy new files - ie files that have not been copied before and compare them to another location where the file has either been renamed or moved !

Upvotes: 1

Views: 1238

Answers (2)

Scott C
Scott C

Reputation: 1660

Pick the order you want to run these lines in (and fix up the mapped drive letters). That said, I'm not sure that you just want to copy both csv and asc files to the Magellan directory as your question mentions comparing them to another location.

echo n|copy /-y z:\*.csv c:\files\Magellan
echo n|copy /-y y:\*.asc c:\files\Magellan\*.csv

Upvotes: 0

npocmaka
npocmaka

Reputation: 57242

@echo off

pushd Z:\

for %%# in (*.csv) do (
  echo n|copy /-Y "%%~f#" "C:\files\Magellan\"
)

for %%# in (*.asc) do (
  echo n|copy /-Y "%%~f#"   "C:\files\Magellan\%%~n#.csv"
)

try this.If your language settings are different than english you might need to change the echo n that applies to your language.Not sure if this can be done with robocopy or xcopy (I need to read their help in details).This will copy/move first the .csv files and then the .asc files . You can change the order and where is needed you can replace the copy command with move

Upvotes: 1

Related Questions