Page 1 of 1
updating a folder
Posted: 07 Oct 2010 06:54
by newbie
Hi, i need help in creating a batch file that can update a file. Let say I have 1 folder (that contain many files) and I duplicated the folder into 2; one i keep it in a desktop and another one i keep it in a pendrive. Everytime I want to update something, I will save it in a pendrive only because i'm getting an information about user pc info and have to bring the pendrive everywhere. In my office, we have 4 technicians and all of them have their own pendrive with the same folder. After they come back to the office, they need to update the information about user pc info on a desktop from the pendrive. So i want to create a batch file that will be placed on a desktop and everytime a technician wants to update they just run the batch file it will update the information from the pendrive to the desktop. Since all the technicians are not getting back to the office at the same time, my question is how to create a batch file that will update a newer file only from all the technicians that come back to the office at a different time?????Tq
Re: updating a folder
Posted: 08 Oct 2010 10:09
by newbie
Need help??!!
Re: updating a folder
Posted: 08 Oct 2010 15:13
by aGerman
I'm not sure about what you would like to do (probably it depends on by bad English knowledge).
Where do the new files come from, always from the USB drives?
What have you to compare? Only if there are newer files on the USB pen? Or if there are newer files on the desktop folder too?
Are these only updated (existing) files or could it be that new files are added?
Please explain.
Regards
aGerman
Re: updating a folder
Posted: 08 Oct 2010 19:53
by newbie
Sorry for the bad english..
Where do the new files come from, always from the USB drives?
Yes, the new files come from the USB drives.
What have you to compare? Only if there are newer files on the USB pen? Or if there are newer files on the desktop folder too?
Yes, only if there are newer files on the USB pen because it will then be copied onto desktop folder
Are these only updated (existing) files or could it be that new files are added?
It will delete existing files from the desktop and replace with the new files from the USB pen.
Re: updating a folder
Posted: 09 Oct 2010 15:50
by aGerman
newbie wrote:Sorry for the bad english..
It's probably better than my English.
OK. Thought about it and maybe this would work.
For my example the USB folder is
D:\Folder and the local folder is
C:\Folder.
Code: Select all
@echo off &setlocal
for %%a in (D:\Folder\*.*) do call :procFile "%%~a" "%%~ta"
pause
goto :eof
:procFile
if not exist "C:\Folder\%~nx1" (
copy %1 "C:\Folder\%~nx1"
goto :eof
)
for /f "tokens=1-5 delims=.-/: " %%a in ("%~2") do set "TimeStampUSB=%%c%%b%%a%%d%%e"
for /f "delims=" %%a in ("C:\Folder\%~nx1") do (
for /f "tokens=1-5 delims=.-/: " %%b in ("%%~ta") do set "TimeStampLocal=%%d%%c%%b%%e%%f"
)
if "%TimeStampUSB%" gtr "%TimeStampLocal%" copy %1 "C:\Folder\%~nx1"
goto :eof
There is one open issue for me. I built the time stamps according the order of
%%~ta for my german settings. It's
dd.mm.yyyy hh:mm but I have no idea if it is different to yours.
Regards
aGerman
Re: updating a folder
Posted: 10 Oct 2010 20:53
by newbie
It works, thnx a lot but what is timestamp for??
Re: updating a folder
Posted: 11 Oct 2010 08:21
by aGerman
CMD is unable to compare DateTime values directly. Thats why you have to separate the single values for day, month, year, hour and minute and reassemble these values to a timestamp with the following formatting
yyyymmddHHMMThese timestamps for the same file on your flash drive and on the hard drive you can compare directly. The greater timestamp belongs to the newer file.
The way how to separate and reassemble, depends on the order and the separator of the incoming data.
You could post the result of this batch file (find it in datetime.txt) here, that we could make sure it would work:
Code: Select all
@echo off &setlocal
cd /d "%SystemRoot%\system32"
for %%a in (cmd.exe) do >"%~dp0datetime.txt" echo %%~ta
Regards
aGerman
Re: updating a folder
Posted: 13 Oct 2010 01:04
by newbie
What if instead of timestamp, I change it to new folder's name, in your example, USB folder is D:\Folder and local folder is c:\Folder,it copies files from USB folder to local folder and rename it to New Folder and compare if the New Folder is exist it will prompt "the files are already exist" and won't copy anything. Is it possible?