Create a text file (copied.txt) which saves the name of the copied files
Moderator: DosItHelp
-
- Posts: 3
- Joined: 24 Jan 2021 02:45
Create a text file (copied.txt) which saves the name of the copied files
Good morning,
I should copy the files from directory A to directory B.
But the files of directory B will be removed after some time.
I only need to copy the new files from directory A that have not yet been copied to directory B.
So I should create a text file (copied.txt) which saves the name of the copied files.
At the end it has to copy in directory B the files of directory A that the name are not in the list of copied files (copied.txt)
I should copy the files from directory A to directory B.
But the files of directory B will be removed after some time.
I only need to copy the new files from directory A that have not yet been copied to directory B.
So I should create a text file (copied.txt) which saves the name of the copied files.
At the end it has to copy in directory B the files of directory A that the name are not in the list of copied files (copied.txt)
Re: Create a text file (copied.txt) which saves the name of the copied files
This is a terrible approach. The log file will grow and searching will take longer and longer. Why don't you move files into an archive folder once they have been copied?
Steffen
Steffen
-
- Posts: 3
- Joined: 24 Jan 2021 02:45
Re: Create a text file (copied.txt) which saves the name of the copied files
So what could be a possible alternative to solve this problem?
As explained previously, the files in directory B will be removed after a certain time. (.Pdf)
So you should be sure to copy only new files from directory A that have never been copied to directory B.
Thanks
As explained previously, the files in directory B will be removed after a certain time. (.Pdf)
So you should be sure to copy only new files from directory A that have never been copied to directory B.
Thanks
Re: Create a text file (copied.txt) which saves the name of the copied files
Well, I already told you an alternative. And you didn't answer my question yet.Crazylife87 wrote: ↑24 Jan 2021 09:01So what could be a possible alternative to solve this problem?
Steffen
Re: Create a text file (copied.txt) which saves the name of the copied files
Code: Select all
@crazylife:
I only need to copy the new files from directory A that have not yet been copied to directory B.
Or am I missing something.
Saso
Re: Create a text file (copied.txt) which saves the name of the copied files
The files will be deleted from folder B, which means they will be copied again. My proposal is to move the files from folder A once they have been copied (e.g. into A\archive or something). The question is whether there is something which prevents to move the files. As an example - the OP isn't authorized, or other users still rely on finding the files in folder A.
In those cases there would be a possibility to do both the logging and the exclusion using a Robocopy job. However, that shouldn't be the preferred solution from my perspective.
Setffen
In those cases there would be a possibility to do both the logging and the exclusion using a Robocopy job. However, that shouldn't be the preferred solution from my perspective.
Setffen
Re: Create a text file (copied.txt) which saves the name of the copied files
Yes, now I see (first I only thought that *some* files will be removed):
As you proposed: move files to archive folder and then copy files from folder A to folder B based on their presence in the archive folder (if not exist archive\%%f copy folder_A\%%f folder_B\).
Saso
Code: Select all
But the files of directory B will be removed after some time.
I only need to copy the new files from directory A that have not yet been copied to directory B.
Saso
-
- Posts: 3
- Joined: 24 Jan 2021 02:45
Re: Create a text file (copied.txt) which saves the name of the copied files
Good morning!
Update:
Basically I should copy the .pdf files from directory A to directory B.
The .pdf files of directory B will be transformed into .csv files (the .pdf one is deleted).
Practically in directory B the file name remains the same with .csv extension.
So I should make a copy based solely on the file name.
Thanks again everyone
Update:
Basically I should copy the .pdf files from directory A to directory B.
The .pdf files of directory B will be transformed into .csv files (the .pdf one is deleted).
Practically in directory B the file name remains the same with .csv extension.
So I should make a copy based solely on the file name.
Thanks again everyone
Re: Create a text file (copied.txt) which saves the name of the copied files
My thinking:
1) copy files *.pdf from A to B
2) move files *.pdf from A to A\archive
Next time all pdf files in A are new files because the old files are moved into the archive folder.
Steffen
1) copy files *.pdf from A to B
2) move files *.pdf from A to A\archive
Next time all pdf files in A are new files because the old files are moved into the archive folder.
Steffen
Re: Create a text file (copied.txt) which saves the name of the copied files
OK, found some time to write 2 examples.
If I was you, that's what should be preferred. Although you never gave any feedback if this makes sense to you, or if this is something which isn't possible for whatever reason.
Following you original request, robocopy would probably be the tool of choice.
Steffen
If I was you, that's what should be preferred. Although you never gave any feedback if this makes sense to you, or if this is something which isn't possible for whatever reason.
Code: Select all
@echo off &setlocal DisableDelayedExpansion
REM create the archive folder if it doesn't exist
if not exist "A\archive\" md "A\archive"
REM pick up file by file
for %%i in ("A\*.pdf") do (
REM check if the file size is greater than 0 to mitigate the risk of copying files which are still about to get written
if %%~zi geq 1 (
REM copy the file to B, then move the file into archive if the copying was successful
>nul copy "%%~i" "B\" &&>nul move "%%~i" "A\archive\"
)
)
pause
Following you original request, robocopy would probably be the tool of choice.
Code: Select all
@echo off &setlocal DisableDelayedExpansion
set "logfile=copied.txt"
set "jobfile=rcpy.rcj"
setlocal EnableDelayedExpansion
REM create a job file for robocopy (run ROBOCOPY /? and see what these options are for)
>"!jobfile!" (
echo /xx
echo /xj
echo /min:1
echo /r:1
echo /w:1
echo /ns
echo /nc
echo /ndl
echo /np
echo /njh
echo /njs
echo /log+:!logfile!
echo /xf
)
REM append names of all files that have been already copied to the /xf option in the job file
>nul copy /b "!jobfile!" + "!logfile!"
REM execute robocopy
robocopy "A" "B" *.pdf /job:"!jobfile!"
REM remove the job file
del "!jobfile!"
REM sort the log file and remove blank lines which have been written for every new job (Win 10 only)
sort /uniq "!logfile!" /o "!logfile!"
pause