1

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 !

npocmaka
  • 55,367
  • 18
  • 148
  • 187
user1044111
  • 57
  • 2
  • 9
  • `The files with the *.asc extension are then processed and then need to be renamed or moved to another directory` - How these files should be renamed.It's not mentioned.My guess is changed extension. – npocmaka May 04 '15 at 11:08
  • Yes - either the extension is renamed or they can be moved into a sub-directory – user1044111 May 04 '15 at 12:06

2 Answers2

1
@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

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • .y:\>(echo n | copy /-Y "y:\ELISA0043.CSV" "C:\files\Magellan\" ) Overwrite C:\files\Magellan\ELISA0043.CSV? (Yes/No/All): n 0 file(s) copied. – user1044111 May 05 '15 at 19:28
  • Thanks npocmaka My language is English and the first part worked perfectly. It detects if there is a file of the same name and doesn`t copy it - which is exactly what is required. How would I add a write to a log file? – user1044111 May 05 '15 at 19:31
  • @nopocmaka, I have this copy command which works fine, however when I issue the move I want to have the file renamed in the destination folder in robocopy bat file `START /WAIT robocopy %EFM_EXPORT% %EFM_TEMP% *.CFX /S /NP /R:5 /W:5 /XX /XD *PR *PA *TA *DC *Bypass /MOV /LOG:%EFM_MOVE%` I tried adding a `%filename%` setting it above in my code to match a dateformat, but didn't work either `set filename=Robocopy_%date:~-4,4%-%date:~-7,2%-%date:~-10,2%#%time::=-%.txt` can this be done.? – MethodMan Sep 02 '16 at 14:17
0

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
Scott C
  • 1,660
  • 1
  • 11
  • 18
  • `echo n|copy ..` does not work with wildcards.Will be applied only over the first file. Try to execute it in the console and there will be copied files.More info -> http://ss64.com/nt/copy.html – npocmaka May 04 '15 at 15:15
  • How long since you've tried it? It does work (on Win7 and 2008 at least) – Scott C May 04 '15 at 23:35