Question : Auto file move and rename

Hi guys

Heres my situation:

I have a folder which every few ecs to minutes a file is created with the same name.

I need to copy these files in real time (or close to it) and rename them at the same time with the current time stamp to a different file location.

to be done on a Windows based OS. I hear robocopy is good for this but can it allow me to autorename the file or add the time to the filename?

I assume it something like - move file and rename to new location using robocopy and schedule this task to run every minute....

Any advice?


Answer : Auto file move and rename

Actually RoBoCopy is intended to replicate files and folders with the same name and structure.

SO funny enough even though RoBoCopy is a great Utility you've hit upon an instance where it isn't as well suited.  So instead you are better off doing XCopy for this.

The following script should work, but I haven't test run it as I'm on my way to work (There may be typo somewhere)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
::------------------------------------------------------------------------------------------------::
:: Script: RoboCopy_Backup_Logs.bat         	                                      			  ::
:: Version: 1.0	                                                                                  ::
:: Copyright: Ben Personick                                                                       ::
:: Date: 2010-07-12                                                                               ::
::                                                                                                ::
::                                                                                                ::
:: Desc: Copies Local System settings, and documents to a backup location on the HD it's run from ::
::                                                                                                ::
::------------------------------------------------------------------------------------------------::
:Begin
  ECHO Off
  SET ScriptName=RoboCopy_Backup_Logs
  ECHO ---- Begining %ScriptName%... ----

::------------------------------------------------------------------------------------------------::
:: This section sets up default variable settings and sets the logging directory and file name.   ::
::------------------------------------------------------------------------------------------------::
:Start-Prep
	ECHO off
	CALL :Start-Set-Date
	SET Preamble=%ScriptName% --
	
	::--------------------------------------------------------------------------------------------::
	:: Sets Relative Paths used to Copy later.  												  ::
	::--------------------------------------------------------------------------------------------::
	:: Valid UNC path or Drive letter must be used for SrcDrv, eg. C: or \\computername
	:: No path vriable should end in a \
	SET SrcDrv=C:
	SET SrcDir=dir1\dir2\dir3
	SET SrcFile=YourFilename(No Extention)
	SET SrcExt=Your File Extention (such as .txt without the dot)
	SET SrcFull=%SrcDrv%\%SrcDir%\%SrcFile%.%ScrExt%
	::--------------------------------------------------------------------------------------------::
	:: If DstDrv is Set to NOMATCH it will find the drive the batch file is double-clicked from.  ::
	::--------------------------------------------------------------------------------------------::
	SET DstDrv=C:
	SET DstDir=destination\goes\here
		
	::--------------------------------------------------------------------------------------------::
	:: This section finds the Drive The Batch File is run from for use later in the script        ::
	::--------------------------------------------------------------------------------------------::
	IF %DstDrv% NEQ NOMATCH GOTO End-Find-Drive-Letter
	:Start-Find-Drive-Letter
		Call :Start-Find-DL-Run-From
	:End-Find-Drive-Letter
	ECHO %Preamble% Drive Run From = %DstDrv% --
	IF DstDrv == NOMATCH ECHO THE BATCH WAS NOT RUN FROM A HARD DRIVE!!
	REM IF DstDrv == NOMATCH pause
	IF DstDrv == NOMATCH GOTO :EOF
	
	::--------------------------------------------------------------------------------------------::
	:: Set File Name to include date and time in ISO Format for easy sorting			          ::
	::--------------------------------------------------------------------------------------------::	
	CALL :Start-Set-Date
	SET DstFileFull=%SrcFile%_%TDate%_%TTime%.%ScrExt%
	SET DstFull=%DstDrv%\%DstDir%\%DstFileFull%
	
	::--------------------------------------------------------------------------------------------::
	:: This Section Sets up logging variables.													  ::
	::--------------------------------------------------------------------------------------------::
	SET IDir=%DstDrv%\Admin\%ScriptName%\Logs
	SET ILog=%ScriptName%_%TDate%_%TTime%.Log
	:: To Turn Off Logging --> SET IDL=nul
	SET IDL=%IDir%\%ILog%
	
	::--------------------------------------------------------------------------------------------::
	:: This Section Creates Directories for Logging and other files								  ::
	::--------------------------------------------------------------------------------------------::
	:Start-Create-Directories
		IF "%IDL%"=="nul" set IDir=nul
		For /F %%D IN ("%IDir%") DO CALL :Start-DIR-Loop %%D
		GOTO End-DIR-Loop
		:Start-DIR-Loop
			SET TDir=%1
			IF %TDir%=="nul" GOTO :EOF
			ECHO %Preamble% Checking For %TDir%
			IF EXIST %TDir% CALL :Start-Echo "%TDir% -- Found!"
			IF EXIST %TDir% GOTO :EOF
			ECHO %Preamble% Creating %TDir%
			MKDir %TDir%
			CALL :Start-Echo "Created %TDir%"
			GOTO :EOF
		:End-DIR-Loop
		CALL :Start-Echo "Dir-Loop Completed"
	:End-Create-Directories
	

:End-Prep

:Start-Begin-Log
	CALL :Start-Set-Date
	CALL :Start-Echo " "
	CALL :Start-Echo "------------------------------------------------------"
	CALL :Start-Echo "BEGIN %ScriptName% Script on %TDate% AT %TTime%"
	CALL :Start-Echo "------------------------------------------------------"
	CALL :Start-Echo " "
:End-Begin-Log

:Start-Main




	::--------------------------------------------------------------------------------------------::
	:: Set File Name to include date and time in ISO Format for easy sorting			          ::
	::--------------------------------------------------------------------------------------------::	
	CALL :Start-Set-Date
	SET DstFileFull=%SrcFile%_%TDate%_%TTime%.%ScrExt%
	SET DstFull=%DstDrv%\%DstDir%\%DstFileFull%
	
	:Start-Copy
		CALL :Start-Echo "Running: XCopy %SrcFull% %%DstFull%% /Z /G /V /Y"
		XCopy "%SrcFull%" "%DstFull%" /Z /G /V /Y
	:End-Copy

:End-Main
GOTO :End


GOTO End-Subs
GOTO :End
:Start-Subs
	GOTO :End-Set-Date
	:Start-Set-Date
		SET TDate=%date:~10,4%-%date:~4,2%-%date:~7,2%
		SET TTime=%Time:~0,2%.%Time:~3,2%.%Time:~6,2%
		GOTO :EOF
	:End-Set-Date
	GOTO End-Echo
	:Start-Echo
		Set TEcho=%~1
		ECHO %Preamble% %TEcho% --
		ECHO %Preamble% %TEcho% -- >> %IDL%
		GOTO :EOF
	:End-Echo
	GOTO End-Find-DL-Run-From
	:Start-Find-DL-Run-From
		FOR %%V IN (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z) DO call :Start-DL-Loop %%V
		GOTO End-DL-Loop
		:Start-DL-Loop
			If %DstDrv% NEQ NOMATCH GOTO :EOF
			SET TDrv=%1:
			REM ECHO %Preamble% TDrv = %TDrv% --
			Dir /D | FIND " Directory of " | Find "%TDrv%\"
			IF ERRORLEVEL 1 GOTO :EOF
			SET DstDrv=%TDrv%
			GOTO :EOF
		:End-DL-Loop
		REM Echo %Preamble% End-DL-Loop --
		GOTO :EOF
	:End-Find-DL-Run-From

:End-Subs


:End
	CALL :Start-Set-Date
	CALL :Start-Echo "!!--!! %ScriptName% Exiting ON %TDate% AT %TTime% !!--!!
	GOTO :EOF
Random Solutions  
 
programming4us programming4us