Batch file required to move rars and zips by any inside file date
Moderator: DosItHelp
Batch file required to move rars and zips by any inside file date
Hi all...
Please help if you can.
I need a batch file to search inside over 100 rar and zip files and move the rar or zip files to a folder according to a year of any file inside.Here is what I tried last.....didn't work....
@ echo off
md 2016files
echo IN PROGRESS PLEASE WAIT
for %%F in (*rar,*.zip) do "C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /m /i /e "2016" >NUL && move "%%F" 2016files >NUL
echo rar and zip files with any file dated 2016 moved to 2016files folder successfully
pause
exit /b
Thanks!
Val
Please help if you can.
I need a batch file to search inside over 100 rar and zip files and move the rar or zip files to a folder according to a year of any file inside.Here is what I tried last.....didn't work....
@ echo off
md 2016files
echo IN PROGRESS PLEASE WAIT
for %%F in (*rar,*.zip) do "C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /m /i /e "2016" >NUL && move "%%F" 2016files >NUL
echo rar and zip files with any file dated 2016 moved to 2016files folder successfully
pause
exit /b
Thanks!
Val
Re: Batch file required to move rars and zips by any inside file date
You sort of have the right idea and I had this third party software installed so you can try this untested code. It requires the year as the first argument.If you are satisfied, swap the remarked code lines to enable your move code. You attempted to use the /M and /e tags of findstr inappropriately. On examining the output of this utility, I found the year to be at the beginning of the line. The /m tag is for a filename that you are not actually searching. Findstr is only being passed a stream of data from the utility. Also, please use code tag when posting code.
I do not share your environment as to file and script file location, so I tested using this:
John A.
Code: Select all
@Echo Off & SetLocal
Set "year=%~1"
md %year%files
echo IN PROGRESS PLEASE WAIT
for %%F in (*rar,*.zip) do "C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /r /c:"^%year%-" >NUL && echo "%%F" has %year% data || echo "%%F" skipped
rem for %%F in (*rar,*.zip) do "C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /r /c:"^%year%-" >NUL && move "%%F" 2016files >NUL
rem echo rar and zip files with any file dated 2016 moved to 2016files folder successfully
echo rar and zip files with any file dated %year% classified successfully
pause
exit /b
I do not share your environment as to file and script file location, so I tested using this:
Code: Select all
@Echo Off & SetLocal
Set "year=%~1"
for %%F in (%userprofile%\Downloads\*.zip) do (
"C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /r /C:"^%year%-" >nul && Echo "%%F" has %year% data || Echo "%%F" skipped
)
exit /b
John A.
Re: Batch file required to move rars and zips by any inside file date
thefeduke
Sorry for the late reply....been super busy.
Sorry but I am not very good at batch files and terminology.
I don't understand what you mean by "please use code tag when posting code."
What is a "code tag"?
Is this the correct way of writing this batch file when you said "It requires the year as the first argument."
The code I tried is this one you gave me( I replaed the first "year" word with the 2016 as shown:
@Echo Off & SetLocal
Set "2016=%~1"
md %year%files
echo IN PROGRESS PLEASE WAIT
for %%F in (*rar,*.zip) do "C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /r /c:"^%year%-" >NUL && echo "%%F" has %year% data || echo "%%F" skipped
rem for %%F in (*rar,*.zip) do "C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /r /c:"^%year%-" >NUL && move "%%F" 2016files >NUL
rem echo rar and zip files with any file dated 2016 moved to 2016files folder successfully
echo rar and zip files with any file dated %year% classified successfully
pause
exit /b
All this does it says data found, BUT it finds ALL files that were made in other years than 2016 also.
I did another test in a test folder with a few copied rar and zip files,removed the "rem" words,and it made 1 file with no file extension and removed all the test files into that 1 file.The rar and zips were no longer there.I added a .zip to the file that had no extension.extracted what was in there and only 1 file extracted....I had 4 files in this test folder with only 2 having been made in 2016.
Please advise...
Thanks
Sorry for the late reply....been super busy.
Sorry but I am not very good at batch files and terminology.
I don't understand what you mean by "please use code tag when posting code."
What is a "code tag"?
Is this the correct way of writing this batch file when you said "It requires the year as the first argument."
The code I tried is this one you gave me( I replaed the first "year" word with the 2016 as shown:
@Echo Off & SetLocal
Set "2016=%~1"
md %year%files
echo IN PROGRESS PLEASE WAIT
for %%F in (*rar,*.zip) do "C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /r /c:"^%year%-" >NUL && echo "%%F" has %year% data || echo "%%F" skipped
rem for %%F in (*rar,*.zip) do "C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /r /c:"^%year%-" >NUL && move "%%F" 2016files >NUL
rem echo rar and zip files with any file dated 2016 moved to 2016files folder successfully
echo rar and zip files with any file dated %year% classified successfully
pause
exit /b
All this does it says data found, BUT it finds ALL files that were made in other years than 2016 also.
I did another test in a test folder with a few copied rar and zip files,removed the "rem" words,and it made 1 file with no file extension and removed all the test files into that 1 file.The rar and zips were no longer there.I added a .zip to the file that had no extension.extracted what was in there and only 1 file extracted....I had 4 files in this test folder with only 2 having been made in 2016.
Please advise...
Thanks
Re: Batch file required to move rars and zips by any inside file date
val5662 wrote:Is this the correct way of writing this batch file when you said "It requires the year as the first argument."
The code I tried is this one you gave me( I replaed the first "year" word with the 2016 as shown:Code: Select all
@Echo Off & SetLocal
Set "2016=%~1"
md %year%files
When you were not satisfied with the results and tested the MOVE code it had to be expected that it would fail also, but thanks for the diagnostic info. My example did not generalize your move code, so here it is for consistency:thefeduke wrote:If you are satisfied, swap the remarked code lines to enable your move code.Code: Select all
@Echo Off & SetLocal
Set "year=%~1"
md %year%files
Code: Select all
rem for %%F in (*rar,*.zip) do "C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /r /c:"^%year%-" >NUL && move "%%F" %year%files >NUL
rem echo rar and zip files with any file dated %year% moved to %year%files folder successfully
So here are the forensics: Assuming that the passed argument was "2016", my code set the variable year to 2016 allowing the directory to be created as '2106files' and the search argument to be '2016-'. Your test left the variable year undefined and set a variable named 2016 to have a value of 2016. This variable is never used later, but now the directory is created as 'files' and the search argument is '-' after the nul value of %year% is substituted. It seems that the '-' is always found and your hard-coded MOVE directory '2016files' does not exist and is treated as a new sequential file and reused, making things disappear. The overwrite switch is set to /-Y when running in a batch script or you would have been prompted for permission. Suggestion untested, but might do more now.
John A.
Re: Batch file required to move rars and zips by any inside file date
Sorry thefeduke....
I am lost.I am not a professional batch maker or understand all the terminology you just said.
If you can please give me the exact batch coding I would need in my case.
More info if you need it:
I want to put the batch files inside a directory full of rars and zips and make a folder there called 2016files and search inside all the rars and zips to find any file that was made in 2016 and move that rar or zip file into that 2016files folder and leave all the rest alone.
Thanks!
I am lost.I am not a professional batch maker or understand all the terminology you just said.
If you can please give me the exact batch coding I would need in my case.
More info if you need it:
I want to put the batch files inside a directory full of rars and zips and make a folder there called 2016files and search inside all the rars and zips to find any file that was made in 2016 and move that rar or zip file into that 2016files folder and leave all the rest alone.
Thanks!
Re: Batch file required to move rars and zips by any inside file date
OK. I have built no check on the validity of the argument as you pass it. You need to delete the target directory when you do the REMARK swap.Just put this script in your directory with the zip files.
Code was edited to suit topic owner.
John A
Code: Select all
@Echo Off & SetLocal
Set "year=%~1"
:: The desired year can be changed in the following line before each run
If Not Defined year Set Year=2001
md %year%files
For %%F in (*rar,*.zip) do "C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /r /c:"^%year%-" >NUL && copy /-Y "%%F" /B %year%files /B || Echo "%%F" skipped
rem for %%F in (*rar,*.zip) do "C:\Program Files\7-Zip\7z.exe" l "%%F" | findstr /r /c:"^%year%-" >NUL && move /-Y "%%F" %year%files || Echo "%%F" skipped
pause
exit /b
Code was edited to suit topic owner.
John A
Last edited by thefeduke on 12 Jul 2017 23:14, edited 1 time in total.
Re: Batch file required to move rars and zips by any inside file date
Yo John A...
I am lost.Let me explain in detail.
I put the batch file in a test folder with 2 rars and 2 zips file that had files inside that were made in different years.
3 had files dated 2003.1 had files dated 2001.When I ran the test batch exactly as I copied from your last post,it copied all 4 files into a folder called files.What I wanted was just the rar or zip files (just copied and moved for this test) into the "files" folder that had only the 2003 dated files inside.It copied and moved all 4.
Was I supposed to put the 2003 date somewhere in the batch file you provided?
Thanks again.Sorry for all the questions I have......
Val
I am lost.Let me explain in detail.
I put the batch file in a test folder with 2 rars and 2 zips file that had files inside that were made in different years.
3 had files dated 2003.1 had files dated 2001.When I ran the test batch exactly as I copied from your last post,it copied all 4 files into a folder called files.What I wanted was just the rar or zip files (just copied and moved for this test) into the "files" folder that had only the 2003 dated files inside.It copied and moved all 4.
Was I supposed to put the 2003 date somewhere in the batch file you provided?
Thanks again.Sorry for all the questions I have......
Val
Re: Batch file required to move rars and zips by any inside file date
OK Val. Let's do it that way. I edited my most recent post to add some code.val5662 wrote:Was I supposed to put the 2003 date somewhere in the batch file you provided?
You can update the year value where indicated and just open the script file. It will also still run from a DOS prompt but you and I no longer need to worry about that.
John A
Re: Batch file required to move rars and zips by any inside file date
John A....
Your last modified code with the "If Not Defined year Set Year=2001" worked 100%.
I appreciate your coding knowledge,time and patience!
Thanks a bunch!
Val
Your last modified code with the "If Not Defined year Set Year=2001" worked 100%.
I appreciate your coding knowledge,time and patience!
Thanks a bunch!
Val