Batch to archive files
Moderator: DosItHelp
Re: Batch to archive files
It processes a folder full of directories.
Re: Batch to archive files
Yes, that is so.
-
- Posts: 38
- Joined: 21 Feb 2013 12:41
Re: Batch to archive files
Just had the chance to test it now.
The result was this http://i.imgur.com/cF6WA0v.png
He did everthing OK but didn't zip the folders at the end.
The result was this http://i.imgur.com/cF6WA0v.png
He did everthing OK but didn't zip the folders at the end.
Re: Batch to archive files
What change did you make?
-
- Posts: 38
- Joined: 21 Feb 2013 12:41
Re: Batch to archive files
This is what I current have.
I changed what you said.
I changed what you said.
Code: Select all
@echo off
call :getdate today -30
set "folder=%cd%"
:: get timestamp in YYYYMMDD_HHMMSS format
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set dt=%dt:~0,8%_%dt:~8,6%
:: To specify the location of the file from where we import the list of directories to take action
set file=C:\MTSOMS\Scripts\FileArchiver\3_folders_WebBox.txt
:: To specify the location of the file from where we filters the files we don't want to archive
set exclusion=C:\MTSOMS\Scripts\FileArchiver\3_filters_WebBox.txt
:: To specify the location of the program that will handle the compression
set programzip=C:\Program Files\7-Zip\7z.exe
::for /f "delims=" %%a in ('dir /a:d /b') do (
for /f "delims=" %%a in (%file%) do (
pushd "%%a"
for /f "delims=" %%b in ('dir /b ^|findstr /v /g:%exclusion%') do (
for /f "tokens=1,2,3 delims=/-" %%c in ('forfiles /M "%%b" /c "cmd /c echo @fdate"') do (
echo checking "%%b"
forfiles /m "%%b" /d -%day% /c "cmd /c MD 0x22%%e_%%d0x22 2>nul & move @file 0x22%%e_%%d0x22 >nul & >>0x22%folder%\%dt%.log0x22 echo %dt%;@file;moving @file to 0x22%dt%-%%e_%%d0x22.zip"
)
)
popd
)
SET LOG_FOLDER=C:\
SET datetime="%date:~6,4%%date:~3,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,2%"
SET LOG_FILE=%LOG_FOLDER%\LOG_%datetime%.CSV
::for /f "delims=" %%a in ('dir /a:d /b') do (
for /f "delims=" %%a in (%file%) do (
pushd "%%a"
md Archive
for /f "delims=" %%b in ('dir "????_??" /ad /b') if /i not "%%b"=="Archive" do (
pushd "%%b"
echo %%a;%%b>>%LOG_FILE%
echo Making ZIP file from "%%b" folder
"%programzip%" a -r -tzip "%%b_%dt%.zip" *
move "%%b_%dt%.zip" .. >nul
popd
rd /s /q "%%b"
move /y "%%b_%dt%.zip" Archive
)
popd
)
pause
goto :EOF
:getdate
:: Date foward & backward
@echo off
:: from code by Phil Robyn
setlocal
if [%1]==[] (
echo to get todays date use
echo call "%~n0" today 0
echo.
echo to get yesterdays date use
echo call "%~n0" today -1
echo.
echo to get the date 25 days ago:
echo call "%~n0" today -25
echo.
echo to get the date 1250 days in the future
echo call "%~n0" today +1250
goto :EOF)
set date1=%1
set qty=%2
if /i "%date1%" EQU "TODAY" (
set date1=now
) else (
set date1="%date1%"
)
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs" right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs" right(100+day(s),2)
for /f %%a in (
'cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& set "day=%result:~6,2%-%result:~4,2%-%result:~0,4%"
:: echo %%day%% is set to "%day%" (without the quotes)
Re: Batch to archive files
That change is only going to stop a folder called 'archive' from being processed.
Something else is going on here I think.
Something else is going on here I think.
-
- Posts: 38
- Joined: 21 Feb 2013 12:41
Re: Batch to archive files
Well I just replaced again and the zip worked fine
-
- Posts: 38
- Joined: 21 Feb 2013 12:41
Re: Batch to archive files
I've tested several times now and what's causing the script to break is this instruction:
for /f "delims=" %%b in ('dir "????_??" /ad /b') if /i not "%%b"=="Archive" do (
If I replaced with the previous one it is ok:
for /f "delims=" %%b in ('dir "????_??" /ad /b') do (
Do you have any idea what's wrong?
for /f "delims=" %%b in ('dir "????_??" /ad /b') if /i not "%%b"=="Archive" do (
If I replaced with the previous one it is ok:
for /f "delims=" %%b in ('dir "????_??" /ad /b') do (
Do you have any idea what's wrong?
Re: Batch to archive files
tiagocampos wrote:I've tested several times now and what's causing the script to break is this instruction:
for /f "delims=" %%b in ('dir "????_??" /ad /b') if /i not "%%b"=="Archive" do (
If I replaced with the previous one it is ok:
for /f "delims=" %%b in ('dir "????_??" /ad /b') do (
Do you have any idea what's wrong?
The do was in the wrong spot. You must have been getting error messages on the console...
Try this:
Code: Select all
for /f "delims=" %%b in ('dir "????_??" /ad /b') do if /i not "%%b"=="Archive" (
-
- Posts: 38
- Joined: 21 Feb 2013 12:41
Re: Batch to archive files
Indeed that fixed it.
I wasn't getting error messages, at least I couldn't see them cause the window shuts down too fast.
I even tried doing some echos/pauses before and after that line to try and figure it out but no luck.
Thanks for your help, now I'll test and see if the problem with the previous Archives being deleted is fixed, although it worked now I must test with a full archive to ensure it's solved.
I wasn't getting error messages, at least I couldn't see them cause the window shuts down too fast.
I even tried doing some echos/pauses before and after that line to try and figure it out but no luck.
Thanks for your help, now I'll test and see if the problem with the previous Archives being deleted is fixed, although it worked now I must test with a full archive to ensure it's solved.