Batch file to move and reorganize files and folders.
Moderator: DosItHelp
Batch file to move and reorganize files and folders.
Hello,
I have a program at work that exports reports (PDF) every night for archival purposes, but the file and folder names are not user friendly.
Every night it creates a folder that has yesterday's date as name in this format ddmmyy (yesterday's folder is 160614).
What I would like is to have a batch file that would run with a scheduled task every morning and find yesterday's folder, copy its content, paste them to a network share and rename the files.
I would like the destination to have this kind of structure: Containing_folder/2014/June/16/"files"
The files will be accessible on \\servername\d$\audit and should be sent to \\servername\d$\Public
One of the file names is GLTB.PDF
Your help would be greatly appreciated, and please let me know if i can give you any extra info.
Thanks,
Kona
I have a program at work that exports reports (PDF) every night for archival purposes, but the file and folder names are not user friendly.
Every night it creates a folder that has yesterday's date as name in this format ddmmyy (yesterday's folder is 160614).
What I would like is to have a batch file that would run with a scheduled task every morning and find yesterday's folder, copy its content, paste them to a network share and rename the files.
I would like the destination to have this kind of structure: Containing_folder/2014/June/16/"files"
The files will be accessible on \\servername\d$\audit and should be sent to \\servername\d$\Public
One of the file names is GLTB.PDF
Your help would be greatly appreciated, and please let me know if i can give you any extra info.
Thanks,
Kona
Re: Batch file to move and reorganize files and folders.
Kona wrote:I would like the destination to have this kind of structure: Containing_folder/2014/June/16/"files"
Using month names will stop the folders sorting correctly.
How do you want the files renamed? You didn't say.
Re: Batch file to move and reorganize files and folders.
Ok, didn't think about that.
Then "01 January" would be fine.
For the example I gave you the filename should be "Guest Ledger Trial Balance"
Thanks
Then "01 January" would be fine.
For the example I gave you the filename should be "Guest Ledger Trial Balance"
Thanks
Re: Batch file to move and reorganize files and folders.
This will sort properly - containing folder\2014\06\16\files
Do you only have one file in your folders?
Do you only have one file in your folders?
Re: Batch file to move and reorganize files and folders.
Ok that's fine.
No I have 16, but I'm in the process of changing them so I'll change them myself in the file.
No I have 16, but I'm in the process of changing them so I'll change them myself in the file.
Re: Batch file to move and reorganize files and folders.
Test this to see if it copies the folder.
Code: Select all
@echo off
set day=-1
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YY=%result:~2,2%"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "data=%yyyy%\%mm%\%dd%"
set "folder=%dd%%mm%%yy%
for /d /r "\\servername\d$\audit" %%a in (%folder%*) do robocopy "%%a" "\\servername\d$\Public\%data%" /mir
pause
Re: Batch file to move and reorganize files and folders.
Works great, makes the directories exactly as expected.
If it could also only copy and rename the files we specify (there is one file in there i don't need) it would be awesome.
Thanks!
If it could also only copy and rename the files we specify (there is one file in there i don't need) it would be awesome.
Thanks!
Re: Batch file to move and reorganize files and folders.
Kona wrote:If it could also only copy and rename the files we specify (there is one file in there i don't need) it would be awesome.
Thanks!
The batch file is using Robocopy to copy the files. I bet if you read the help file for that command you would see this.
Code: Select all
/XF file [file]... :: eXclude Files matching given names/paths/wildcards.
Re: Batch file to move and reorganize files and folders.
ok, i will take it from here then.
Thanks a lot !
Thanks a lot !