Using 7zip to archive file by older than 5 daya - 7zip

i wanted to archive folder olden than 5 days.it seems set ARCHIVE_FILE_OLDER_THEN=-to5d is not working. can someone what i can add to archive files to 5 days .Previously it was working for RAR but not working 7z
set EDI832_US_ARCHIVE_DIR=C:\apps\harmony\data\EDI832\US\archive
REM -------------------- FILE NAME LIST ---------------------------------
set EDI832_US_FILE=EDI832_US_ARCHIVE
REM --------------- Extra CommandLine Parameters --------------------------------
REM Exclude file types for archiving
REM set EXCLUDE_FILES_TYPES=-x!*.rar -x!*.zip -x!*.7z
set EXCLUDE_FILES_TYPES=-xr!*.zip
REM Delete files after archiving
set DELETE_AFTER_ARCHIVE=-sdel
REM Archive files only older then days
set ARCHIVE_FILE_OLDER_THEN=-to5d
set EXTRA_PARAM=%EXCLUDE_FILES_TYPES% %DELETE_AFTER_ARCHIVE% %ARCHIVE_FILE_OLDER_THEN%
REM ------------------------------------------------------------------------------------
REM Path to WinRAR executable in Program Files
set path="C:\Program Files\7-Zip";%path%
REM $Env:Path = $Env:Path + ";C:\Program Files\7-Zip"
REM Set your WinRAR installation path for local testing
REM set path="C:\Program Files\7-Zip";%path%
REM Replace space in hour with zero if it's less than 10
SET hr=%time:~0,2%
IF %hr% lss 10 SET hr=0%hr:~1,1%
REM This sets the date like this: mm-dd-yr-hrminsecs1/100secs
Set TODAY=%date:~4,2%-%date:~7,2%-%date:~10,4%-%hr%%time:~3,2%%time:~6,2%%time:~9,2%
IF EXIST %EDI832_US_ARCHIVE_DIR% (
cd %EDI832_US_ARCHIVE_DIR%
**7z a "%EDI832_US_FILE%_%TODAY%" %EXTRA_PARAM%**

Related

Move files into folders in batches of five?

Suppose I have 50 files sorted by name.. I would like to create a batch script which gives me the following result:
Files 1 through 5 -> 01-05
Files 6 through 10 -> 06-10
and so on..How can I create a batch script to achieve this?
Note that 01-05 and 06-10 are directory names..
EDIT: Details
For eg. Consider this:
Source Directory:
101.mp4
102.mp4
103.mp4
104.mp4
and so on..
I want a resulting directory structure like this:
Destination Directory:
101-105:
101.mp4
102.mp4
103.mp4
104.mp4
105.mp4
106-110:
106.mp4
107.mp4
108.mp4
109.mp4
110.mp4
and so on..
This is what you want, change fileCount to change the file number in each subdirectory:
#echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set fileCount=5
set filesNow=0
set nameStart=000
set nameEnd=000
FOR /F "usebackq delims=" %%i IN (`dir /b /O:N *.mp4`) do (
set /a filesNow+=1
set /a tmpValue=filesNow %% fileCount
::echo !filesNow!
::echo !fileCount!
::echo %%i
::echo !tmpValue!
if "!tmpValue!"=="1" (
set "nameStart=%%~ni"
mkdir _tmpDir_
)
move %%~nxi _tmpDir_\
if "!tmpValue!"=="0" (
rename _tmpDir_ !nameStart!-%%~ni
)
set "nameEnd=%%~ni"
)
if exist _tmpDir_ rename _tmpDir_ %nameStart%-%nameEnd%
You need to put them inside a bat/cmd file to work.
filesNow is for file number count.
Basically it's create a tmp folder and move files inside,
When files inside it reach the number, change the folder's name.
Several testing echo command I didn't remove, just used :: to comment them out, you can remove the :: to test them again.

Batch file to generate n amount of folders

Hi I would like to create a batch file which makes n amount of folders and moves them to a specified dir. something like make folders {00001-00009} to put it bluntly. I don't want to manually put each number in and I would like to be able to exclude numbers as well.
so far I have tried this code below. I get the 5 folders made in C:\source\
and I am able to dictate how they are named to an extent, by changing j=5 to whatever integer, however sometimes the file makes folders from 00256-003372 instead of what I specified. this happens when I change j to j=256 and run the program.
echo off
cd C:\source\ :: I included this because for some reason folder 1 copied to root
SET /a j=1
:floop
IF %j%==5 GOTO END
md 00%j%
cd 00%j%
SET /a j=%j%+1
cd C:\source\
GOTO FLOOP
:end
The other way I did this was to manually input each number in a .bat file such as below. which works fine but I have to make a line for each folder.
md C:\Device_Numbers_Folder\00001
md C:\Device_Numbers_Folder\00002
P.S I named the dir file source because I am running a bunch of .bat files with CALL and this is the source part.
I think you want something like this:
#echo off
setlocal EnableDelayedExpansion
::CD "C:\source\"
::only change these three lines
set "start=1"
set "amount=5"
set "length=5"
set "exclude=4,5"
set "excluded=0"
FOR %%G IN (%exclude%) DO (set /a "excluded+=1")
set /a "last=%start%+%amount%+%excluded%"
for /l %%i in (%start%,1,%last%) do (
set "skip=0"
FOR %%G IN (%exclude%) DO (if "%%i"=="%%G" set "skip=1")
if !skip! equ 0 (
set "folderName=0000000000%%i"
set "folderName=!folderName:~-%length%!"
md "!folderName!"
)
)
In this start is the first number, amount is the amount of folder it needs to create, and length is the lenght of the names of the new files, so 1 with length 5 becomes 00001. Exclude is an comma seperated list of all the numbers not allowed

.bat script to compare contents of two windows folders

I would like to write a short .bat script to compare the contents of two folders.
Folder 1: Contains some 1300 files.
Folder 2: Contains some 400 files.
I would like to have a script I can run through the windows command line that takes each file in Folder 2 checks to see if a file with the same name is in Folder 1... and if it is Outputs the name of the Folder 2 file to a .csv file (or notepad I'm easy just want a list!).
Any thoughts or help would be much appreciated!
try this
(for %%i in ("folder2\*") do if exist "folder1\%%~nxi" echo(%%~i)>file.csv
Found a solution that works with remote folders and is very fast
#echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set /p computer=Computer Name?:
set pubpath=\\%computer%\c$\docume~1\alluse~1\Desktop\
set results=excluded
set extension=txt
set xlist="ANHLIVE Desktop.lnk" "ANHLIVE EMR.lnk" "ImageNow.lnk" "IMPAX Client.lnk" "Internet Explorer.lnk" "Microsoft Excel 2010.lnk" "Microsoft Outlook 2010.lnk" "Microsoft Word 2010.lnk" "My Documents.lnk" "NextGen.RDP" "RBODowntimeLabel.doc" "desktop.ini"
set xlistcount=12
for /r %pubpath% %%g in (*) do (
set count=0
for %%a in (%xlist%) do (
set /a count=count+1
set localdir=%%a
set localdir=!localdir:~1,-1!
set remotedir=%%g
set remotedir=!remotedir:%pubpath%=!
if !localdir!==!remotedir! (
set count=12
) else (
if !count!==%xlistcount% (
echo !remotedir! >> %results%.%extension%
)
)
)
)
Echo Complete!
pause

Bat file for moving files

I want to create one bat file that will move files from one location to one backup folder. Condition is I need to move all folders which are older than 30 days inside parent directory. Name of folder is creation date of folder.
For example:
All files of 17 October 2012 would be there inside folder named 10172012.Source folders are:
C:\Data\DataIn\Processed\10172012
C:\Data\DataIn\Processed\09172012
C:\Data\DataIn\Processed\08172012
So on today bat file should move folders "09172012", "08172012" to destination backup folder:
D:\Backup\Processed\
#echo off
setlocal EnableDelayedExpansion
rem Get Julian Day number of today's date
for /F "tokens=1-3 delims=/" %%a in ("%date%") do (
set /A m=1%%a %% 100, d=1%%b %% 100, y=%%c
)
set /A A=(m-14)/12, todayJDN = (1461*(y+4800+A))/4 + (367*(m-2-12*A))/12 - (3*((y+4900+A)/100))/4 + d - 32075
rem Process all folders
for /D %%a in (*) do (
rem Get Julian Day Number of this folder
set folder=%%a
set /A m=1!folder:~0,2! %% 100, d=1!folder:~2,2! %% 100, y=!folder:~4!
set /A "A=(m-14)/12, folderJDN = (1461*(y+4800+A))/4 + (367*(m-2-12*A))/12 - (3*((y+4900+A)/100))/4 + d - 32075"
rem Move folder if it is older than 30 days
set /A daysOlder=todayJDN - folderJDN
if !daysOlder! gtr 30 move %%a D:\Backup\Processed\
)
Julian Day Numbers are described here: http://www.hermetic.ch/cal_stud/jdn.htm
Using shell scripting it was easier to do. Finally I implemented this using shell scripting.

Creating a batch file to back up a specified folder

I am actually pretty new to this batch file thing. I know it's important to know at least the basic commands. How do I do the following?
Zipping a specified folder.
Move the folder to another place.
When zipping it, the ZIP file name will be the current date and
if there is another zipped file with the same name, it should be named like 20090924-2.
PS: 7-Zip is installed on my computer as an archive software.
The batch script listed below will do it (I have tested it
and it works to specifications). The directory to zip and
move is specified as its parent directory and the name of
the directory (PARENT_FOLDERTOZIP and FOLDERTOZIP in the
beginning) - I couldn't figure out how to copy entire
directories (I think XCOPY can only copy content of
directories and sub-directories.). The copy location is
specified as FOLDERTARGETLOCATION, and the directory to place
the compressed files in is specified as ZIPDIR.
The location of 7-Zip is configured through SEVENZIP_EXE.
Note also that getting the current date in the required
format depends on the short date format in regional
settings. I have listed three different versions for
ISO-8601, Central European and U.S.A. The active one in the
listing is for the U.S.A. (the "set FDATE=" line). If a
different one is needed then just copy-paste from one of the
other two.
That said it should be noted that this kind of thing is much
easier with Perl, Python or PowerShell.
#echo off
#title=Folder zip and move...
rem Parameters
rem Folder to zip and move
set PARENT_FOLDERTOZIP=T:\to delete
set FOLDERTOZIP=Folder to Compress
rem Target folder for moving the input folder to.
set FOLDERTARGETLOCATION=s:\move Here
rem Where to place compressed folders
set ZIPDIR=D:\toDelete\2009-09-24a
rem Configuration
set SEVENZIP_EXE=D:\Program Files\7-Zip\7z.exe
rem =================== Date ==============================================
rem There is no universal way inside batch itself to get a
rem date that is independent of regional settings (but is
rem quite trivial if an external program or script
rem (Perl/Python) is available).
rem
rem For short date formats:
rem
rem -------------------------------------------------------
rem
rem ISO-8601:
rem 0123456789
rem yyyy-MM-dd/ E.g.: 2009-09-24
rem
rem set FDATE=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%
rem
rem -------------------------------------------------------
rem
rem Central european:
rem 0123456789
rem dd/MM/yyyy E.g.: 24/09/2009
rem
rem set FDATE=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%
rem
rem -------------------------------------------------------
rem
rem US:
rem
rem 0123456789
rem MM/dd/yyyy E.g.: 09/24/2009
rem
rem set FDATE=%DATE:~6,4%%DATE:~0,2%%DATE:~3,2%
set FDATE=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%
set ZIPFILE=%ZIPDIR%\%FDATE%.7z
set FOLDERTOZIP_FULLPATH=%PARENT_FOLDERTOZIP%\%FOLDERTOZIP%
mkdir %FOLDERTARGETLOCATION%
rem Does a zip file already exist?
if exist "%ZIPFILE%" GOTO L_ZIPFILE_EXISTS
GOTO L_ZIPFILENAME_OK
rem Find a compressed file that does not already exist.
:L_ZIPFILE_EXISTS
set RNUM=0
:L_TRYANOTHER
set /a RNUM=%RNUM% + 1
set ZIPFILE=%ZIPDIR%\%FDATE%-%RNUM%.7z
echo Candidate: %ZIPFILE% ...
if exist "%ZIPFILE%" GOTO L_TRYANOTHER
rem Zip the folder!
:L_ZIPFILENAME_OK
"%SEVENZIP_EXE%" a %ZIPFILE% "%FOLDERTOZIP_FULLPATH%"
if exist "%ZIPFILE%" GOTO L_OKZIP
GOTO L_ERROREND
:L_OKZIP
rem Move folder: copy, then delete source.
set DEST_FOLDER=%FOLDERTARGETLOCATION%\%FOLDERTOZIP%
mkdir "%DEST_FOLDER%"
xcopy /Y /S "%FOLDERTOZIP_FULLPATH%"\*.* "%DEST_FOLDER%"\
rmdir /S "%FOLDERTOZIP_FULLPATH%"
GOTO L_END
:L_ERROREND
echo 7-Zipping failed !!!
:L_END
pause

Resources