Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I am using robocopy to copy files from source to destination folder but there are some problems.

In the source folder .csv files are created by various users every 15-20 mins for example User1.csv, User2.csv, User3.csv. There is an archive folder on the source folder.

These files have to be moved to a destination folder. The files on the destination folder are uploaded to a different application every 30 mins.

Problem: When user1 creates a file user1.csv, it has to be moved to the destination folder. If a file already exists on the destination folder then it should not be moved. But if no file exists on the destination folder then the file needs to be moved and a copy of the file has to be saved on archive folder.

@echo off

SET SORC= "C:\Test\Source" 
SET DEST="C:\Test\Destination"
SET LOG="C:\Test\THE LOG FILE.log"

ROBOCOPY %SORC% %DEST% *.csv /R:1 /W:1 /MOV /XN /XO /LOG:%LOG%

:END


What I have tried:

I am using the above code to move the files.

How can i save the files on the archive folder with the same name every time a new file is created?
Posted
Updated 23-Aug-18 2:07am
v2

1 solution

One solution would be getting the files one by one using a for loop and process them.

Untested:
ECHO Copy session %date% %time%>%LOG%
FOR %%f in (%SORC%\*.csv) do (
    SET fname=%%~nxf
    IF NOT exist %DEST%\%fname% (
        xcopy %%f %SORC%\archive /q
        move /Y %%f %DEST%
        ECHO Copied file %fname%>>%LOG%
    ) ELSE (
        ECHO Skipped file %fname%>>%LOG%
    )
)
 
Share this answer
 
Comments
Dave Kreskowiak 23-Aug-18 9:17am    
I don't know why anyone would you give a 1-vote. It's a perfectly reasonable answer. Countered.
Jochen Arndt 23-Aug-18 13:05pm    
Thank you Dave.
Member 13958091 23-Aug-18 12:54pm    
Any other solutions?
Jochen Arndt 23-Aug-18 13:04pm    
What is the problem with my solution?

However, you may write something similar using PowerShell commands where you have more options.
Member 13958091 23-Aug-18 15:57pm    
I tested it and tried to make it work but no luck.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900