stephensan
asked on
Copy\Move Files into correctly Dated folders
Dear All,
I have a PBX which generates call recordings as wav files and stores them in individual department folders on a windows server as follows
D:\Record\Sales
D:\Record\Finance
D:\Record\Marketing
D:\Record\HR
etc...
What I'd like to do is have a script or a tool which can be scheduled to copy\move the wav files from the windows server onto a storage server in the following format
<drive_letter>:\Record\Sal es\31.05.0 6\*.wav
<drive_letter>:\Record\Sal es\01.06.0 6\*.wav
<drive_letter>:\Record\Sal es\02.01.0 6\*.wav
<drive_letter>:\Record\Fin ance\31.05 .06\*.wav
<drive_letter>:\Record\Fin ance\01.06 .06\*.wav
<drive_letter>:\Record\Fin ance\02.01 .06\*.wav
The above keeps the dept name structure, reads the creation date of the .wav file and then creates a sub-folder under each department with the days date as the folder name before moving all that departments wav files for that date into it.
The solution needs to be able to read the file date and create folders accordingly in case the process does not run on any given day or gets interrupted and as a result the copy\move process has to catch up.
Ideally I'd like something which will copy (for testing) then be capable of being switched to moving (for production).
Hopefully the above makes sense. All ideas are gratefully received.
Cheers
Stephen
I have a PBX which generates call recordings as wav files and stores them in individual department folders on a windows server as follows
D:\Record\Sales
D:\Record\Finance
D:\Record\Marketing
D:\Record\HR
etc...
What I'd like to do is have a script or a tool which can be scheduled to copy\move the wav files from the windows server onto a storage server in the following format
<drive_letter>:\Record\Sal
<drive_letter>:\Record\Sal
<drive_letter>:\Record\Sal
<drive_letter>:\Record\Fin
<drive_letter>:\Record\Fin
<drive_letter>:\Record\Fin
The above keeps the dept name structure, reads the creation date of the .wav file and then creates a sub-folder under each department with the days date as the folder name before moving all that departments wav files for that date into it.
The solution needs to be able to read the file date and create folders accordingly in case the process does not run on any given day or gets interrupted and as a result the copy\move process has to catch up.
Ideally I'd like something which will copy (for testing) then be capable of being switched to moving (for production).
Hopefully the above makes sense. All ideas are gratefully received.
Cheers
Stephen
Depending on your regional date / time settings, this may work (if not, post your DIR output, or change the %%c %%d %%e):
@echo off
set Source=D:\Record
set Dest=E:\Record
set Depts=Finance HR Marketing Sales
rem Function should be COPY or MOVE
set Function=Copy
for %%a in (%Depts%) do call :List %Source% %%a
goto :EOF
:List
for /f "tokens=1,2,3,6* delims=.-/ " %%c in ('dir %1\%2\*.wav ^| findstr /i .wav') do (
if not exist "%Dest%\%2\%%d.%%c.%%e\" md "%Dest%\%2\%%d.%%c.%%e\"
echo %Function%'ing "%1\%2\%%g" to "%Dest%\%2\%%d.%%c.%%e"
%Function% "%1\%2\%%g" "%Dest%\%2\%%d.%%c.%%e" >NUL
)
@echo off
set Source=D:\Record
set Dest=E:\Record
set Depts=Finance HR Marketing Sales
rem Function should be COPY or MOVE
set Function=Copy
for %%a in (%Depts%) do call :List %Source% %%a
goto :EOF
:List
for /f "tokens=1,2,3,6* delims=.-/ " %%c in ('dir %1\%2\*.wav ^| findstr /i .wav') do (
if not exist "%Dest%\%2\%%d.%%c.%%e\" md "%Dest%\%2\%%d.%%c.%%e\"
echo %Function%'ing "%1\%2\%%g" to "%Dest%\%2\%%d.%%c.%%e"
%Function% "%1\%2\%%g" "%Dest%\%2\%%d.%%c.%%e" >NUL
)
ASKER
@GuruGary
Thanks for the reply. I'll run this script today and get back with the results ASAP.
Cheers
Stephen
Thanks for the reply. I'll run this script today and get back with the results ASAP.
Cheers
Stephen
ASKER
Hi,
Ran the script and it creates the folders which match the orginal structure but does not copy the actual wav files themselves.
I changed %%c %%d %%e around in different orders but the files still do not copy over.
Proably something dumb on my side. any ideas?
Cheers
Stephen
Ran the script and it creates the folders which match the orginal structure but does not copy the actual wav files themselves.
I changed %%c %%d %%e around in different orders but the files still do not copy over.
Proably something dumb on my side. any ideas?
Cheers
Stephen
Did you modify any of the variables at the top of the script ... or verify they are correct?
Please provide a sample output that the script gives you, and I will help figure it out.
Like:
Copy'ing "D:\Record\Sales\whatever. wav" to "E:\Record\Sales\31.03.200 6"
Also, provide the output of a DIR command, like:
Directory of C:\
31.05.2006 10:27 AM <DIR> WINDOWS
Please provide a sample output that the script gives you, and I will help figure it out.
Like:
Copy'ing "D:\Record\Sales\whatever.
Also, provide the output of a DIR command, like:
Directory of C:\
31.05.2006 10:27 AM <DIR> WINDOWS
ASKER
Hi, Sorry about the delay, madhouse round here.
Here is a copy of the script as I ran it (server name has been removed because I'm paranoid :-)
************************** ********** ********** ********** ********** **
@echo off
set Source=\\<Server Name>\record
set Dest=c:\record
set Depts=Sales Marketing
rem Function should be COPY or MOVE
set Function=Copy
for %%a in (%Depts%) do call :List %Source% %%a
goto :EOF
:List
for /f "tokens=1,2,3,6* delims=.-/ " %%c in ('dir %1\%2\*.wav ^| findstr /i .wav') do (
if not exist "%Dest%\%2\%%c.%%d.%%e\" md "%Dest%\%2\%%c.%%d.%%e\"
echo %Function%'ing "%1\%2\%%g" to "%Dest%\%2\%%c.%%d.%%e"
%Function% "%1\%2\%%g" "%Dest%\%2\%%c.%%d.%%e" >NUL
)
************************** ********** ********** ********** ********** **
I changed the drive locations and moved the date variables around to read dd.mm.yy in line with the setup on my machine. The folders get created and it looks like the files are being copied but when you go into the folder, nothing. (The file not found is due to one of the source folders being empty).
As requested here is the out from the dir command before and after the copy.
************************** ********** ********** ********** ********** **
C:\record>v:<THis is a mapped drive to the record share>
V:\>dir
Volume in drive V has no label.
Volume Serial Number is ACDA-B575
Directory of V:\
01.06.06 13:34 <DIR> .
01.06.06 13:34 <DIR> ..
10.06.06 02:30 <DIR> Sales
10.06.06 02:55 <DIR> Marketing
4 Dir(s) 75,832,942,592 bytes free
V:\>c:
C:\record>dir
Volume in drive C has no label.
Volume Serial Number is 7C15-863F
Directory of C:\record
10.06.06 09:00 <DIR> .
10.06.06 09:00 <DIR> ..
10.06.06 08:57 516 wavmover.bat
1 File(s) 516 bytes
2 Dir(s) 9,102,295,040 bytes free
C:\record>wavmover.bat
File Not Found
Copy'ing "\\<server name>\record\Marketing\wav " to "c:\record\Marketing\09.
06.06"
C:\record>dir
Volume in drive C has no label.
Volume Serial Number is 7C15-863F
Directory of C:\record
10.06.06 09:01 <DIR> .
10.06.06 09:01 <DIR> ..
10.06.06 09:01 <DIR> Marketing
10.06.06 08:57 516 wavmover.bat
1 File(s) 516 bytes
3 Dir(s) 9,102,295,040 bytes free
C:\record>cd O2*
C:\record\Marketing>dir
Volume in drive C has no label.
Volume Serial Number is 7C15-863F
Directory of C:\record\Marketing
10.06.06 09:01 <DIR> .
10.06.06 09:01 <DIR> ..
10.06.06 09:01 <DIR> 09.06.06
0 File(s) 0 bytes
3 Dir(s) 9,102,295,040 bytes free
C:\record\Marketing>cd 09*
C:\record\Marketing\09.06. 06>dir
Volume in drive C has no label.
Volume Serial Number is 7C15-863F
Directory of C:\record\Marketing\09.06. 06
10.06.06 09:01 <DIR> .
10.06.06 09:01 <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 9,102,295,040 bytes free
C:\record\Marketing\09.06. 06>
************************** ********** ********** ********** ********** **
Here is a copy of the script as I ran it (server name has been removed because I'm paranoid :-)
**************************
@echo off
set Source=\\<Server Name>\record
set Dest=c:\record
set Depts=Sales Marketing
rem Function should be COPY or MOVE
set Function=Copy
for %%a in (%Depts%) do call :List %Source% %%a
goto :EOF
:List
for /f "tokens=1,2,3,6* delims=.-/ " %%c in ('dir %1\%2\*.wav ^| findstr /i .wav') do (
if not exist "%Dest%\%2\%%c.%%d.%%e\" md "%Dest%\%2\%%c.%%d.%%e\"
echo %Function%'ing "%1\%2\%%g" to "%Dest%\%2\%%c.%%d.%%e"
%Function% "%1\%2\%%g" "%Dest%\%2\%%c.%%d.%%e" >NUL
)
**************************
I changed the drive locations and moved the date variables around to read dd.mm.yy in line with the setup on my machine. The folders get created and it looks like the files are being copied but when you go into the folder, nothing. (The file not found is due to one of the source folders being empty).
As requested here is the out from the dir command before and after the copy.
**************************
C:\record>v:<THis is a mapped drive to the record share>
V:\>dir
Volume in drive V has no label.
Volume Serial Number is ACDA-B575
Directory of V:\
01.06.06 13:34 <DIR> .
01.06.06 13:34 <DIR> ..
10.06.06 02:30 <DIR> Sales
10.06.06 02:55 <DIR> Marketing
4 Dir(s) 75,832,942,592 bytes free
V:\>c:
C:\record>dir
Volume in drive C has no label.
Volume Serial Number is 7C15-863F
Directory of C:\record
10.06.06 09:00 <DIR> .
10.06.06 09:00 <DIR> ..
10.06.06 08:57 516 wavmover.bat
1 File(s) 516 bytes
2 Dir(s) 9,102,295,040 bytes free
C:\record>wavmover.bat
File Not Found
Copy'ing "\\<server name>\record\Marketing\wav
06.06"
C:\record>dir
Volume in drive C has no label.
Volume Serial Number is 7C15-863F
Directory of C:\record
10.06.06 09:01 <DIR> .
10.06.06 09:01 <DIR> ..
10.06.06 09:01 <DIR> Marketing
10.06.06 08:57 516 wavmover.bat
1 File(s) 516 bytes
3 Dir(s) 9,102,295,040 bytes free
C:\record>cd O2*
C:\record\Marketing>dir
Volume in drive C has no label.
Volume Serial Number is 7C15-863F
Directory of C:\record\Marketing
10.06.06 09:01 <DIR> .
10.06.06 09:01 <DIR> ..
10.06.06 09:01 <DIR> 09.06.06
0 File(s) 0 bytes
3 Dir(s) 9,102,295,040 bytes free
C:\record\Marketing>cd 09*
C:\record\Marketing\09.06.
Volume in drive C has no label.
Volume Serial Number is 7C15-863F
Directory of C:\record\Marketing\09.06.
10.06.06 09:01 <DIR> .
10.06.06 09:01 <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 9,102,295,040 bytes free
C:\record\Marketing\09.06.
**************************
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The solution provided by GuruGary on 5/31 combined with with the update on 6/20 should be a complete solution that solves all parts of the problem.
Example:
Directory of C:\
31.05.2006 10:27 AM <DIR> WINDOWS
And if the DIR command gives a 4-character year, do you want that truncated to 2 digits?