# Solved: rename file based on timestamp



## Swiper (Mar 14, 2003)

Hi
hope someone can help a guy out here

have scanner which scans files for example as xxx_001.jpg, xxx_002.jpg, xxx_003.jpg
these files get transferred(moved) through a remote desktop session to be use on a remote server
however, problem is once, the files are moved to the server and y ou scan more files, the software will once again start the scanning, and naming of the file as indicated before as xxx_001.jpg, xxx_002.jpg, xxx_003.jpg. Now, when we try to copy them over, they are recognized as already being done (even though they are new files ) and wants to overwrite them

I don't want to over write them though


any easy way to get this done ?


----------



## foxidrive (Oct 20, 2012)

A solution is to leave all the JPG files there and allow a batch file to change all JPG files to zero bytes, so they don't take up any room, and the scanning software can continue adding higher numbers.

The process where you move the files would instead simply copy the files that are not zero bytes, and afterward run a batch file to zero all the JPG files in the folder (this would include the ones that are already zero, and that isn't an issue).

This is the script to zero all JPG files in the folder.


```
@echo off
for %%a in (*.jpg) do type nul>"%%a"
```


----------



## Swiper (Mar 14, 2003)

I don't want to make them all 0 
I want find ability to 
a) rename/based on timestamp to include milliseconds or fractions of a second OR
b) have the batch NOT overwrite a file, but simply write it as a copy of it.... ( or put an filename_a.jpg ) filename_b.jpg ) on it
to show them as different files , even if they were created on same mm/dd/yyyy/hh/mm/ss


----------



## foxidrive (Oct 20, 2012)

*EDIT: I simplified the script
*
Run this in the folder with the JPG files - it will list the rename commands to the screen but it doesn't go to millisecond accuracy. A scan will take more than one second though, correct?

Remove the REM from the batch file near the bottom to make it actually perform the renaming of the files.
and put REM in front of the line starting with type


```
@echo off
:loop
set "file=%temp%\renfile-%random%.vbs"
if exist "%file%" goto :loop

:: change the filespec here

dir "d:\folder\*.jpg" /b /a-d >"%file%.list"

(
 echo. Const ForReading = 1, ForWriting = 2
 echo. infile = "%file%.list"
 echo. Set fso = CreateObject("Scripting.FileSystemObject"^)
 echo. Set f1 = fso.OpenTextFile(infile, ForReading^)
 echo. WScript.Echo "@echo off"
 echo. Do While not f1.AtEndOfStream
 echo. Set f = fso.GetFile(f1.readline^)
 echo. ' n = f.DateLastAccessed
 echo. ' n = f.DateCreated
 echo. n = f.DateLastModified
 echo. WScript.Echo "ren "+chr(34^)+f+chr(34^)+" "+chr(34^)+CStr(Year(n^)^)+Right(100+Month(n^),2^)+Right(100+Day(n^),2^)+"_"+Right(100+Hour(n^),2^)+"h"+Right(100+Minute(n^),2^)+"m"+Right(100+Second(n^),2^)+"s_"+f.name+chr(34^)
 echo. loop
 echo. f1.close
)>"%file%"
cscript //nologo "%file%" >"%file%.bat"


REM call "%file%.bat"
type "%file%.bat"&pause

del "%file%" "%file%.bat"  "%file%.list"
```


----------



## Swiper (Mar 14, 2003)

wow, that seems to work pretty nice
THANKS ALOT! 


is there anyway I can have the bat file stored and run from different directory using this ?
where would I put the path to


for example
i'd like to have this.bat file on C:\Batches\ 
i'd like the user to run C:\Batches\this.bat 
problem is, I have all my "tif or jpg" files in C:\Scanned folder

the script assumes my 'tif or jpg" files are located in same directory as the bat which I prefer not to
if at all possible
Can this be done ?

'hope I explained that properly"
hehe


----------



## foxidrive (Oct 20, 2012)

I changed the script to simplify it.

On line with the filespec add /s before the /b and it will run in any folder.

This assumes that the folder that you have the JPG files in do not have any subdirectories, as if any exist then they will be processed too.


----------



## Swiper (Mar 14, 2003)

Thanks again !!

Muchly appreciated ............


----------

