I am trying to create a batch file that searches a folder for zipped files, and unzip them. I want the script to search through all the subfolders in the main folder, and unzip everything it finds. It might be a main folder with several subfolders. Some of the subfolders will contain zipped files, but some will not.
The zipped files will look like "filename.r00", "filename.r01", "filename.r02", and so on. One file will have the name "filename.rar", and it is this file that will need to extracted using 7-zip.
Is it possible to write a batch file that does this, and then deletes all the zip files? I have already installed 7-zip, so if it is possible I would like to use it. If anyone could help me write the batch file, it would be much appreciated!
Thanks!
Here you go
for /r C:\Mainfolder %%a in (filename.r*) do (
7z e %%a -o%%a_Extracted
del %%a /f /q
)
After looking at the switches for 7-Zip this might be faster (untested)
7z x filename.r* -o*_Extracted -r
del filename.r* /f /q
Either way they are extracted to a folder with _Extracted at the end, otherwise it will extract them to a folder with the same name as the archive, and when it deletes the files, it may try and delete the folders too.
Related
I am trying to create a batch file that will unzip files in a folder using 7-zip and then once the files have been unzipped, moved the zip files to a different folder.
So far, I have a batch file that does the following.
7z.exe x q:\*.zip -op:\
move q:\*.zip q:\Completed
I don't want the move feature to work until after the zip process completes.
Under normal circumstances that should be the case. If some zip's might be added to q: while moving it gets difficult.
To have better control you should use a for to unzip single zips and move only if successful.
#Echo off
Pushd q:\
For %%A in (*.zip) Do 7z.exe x -op:\ "%%A" && Move "%%A" q:\completed
popd
This may be a bit slower.
I'm often compressing folders of images or other project related documents into separate zip files the current command in a bat file I'm using is.
for /d %%X in (*) do "D:\Program Files\7-Zip\7z.exe" a "%%X.7z" "%%X\"
It automatically places the full contents of all folders separate archive files.
My question is if you double click on any of the archives it first navigates to a a folder of the same name as the archive. Is there a way to make it so it doesn't put have to folder, it just has the contents?
Right now I get
D:\User\1501.7z\1501\ contents
I just want
D:\User\1501.7z\ contents
Second if this is possible can it be set up so that if one of the folders has multiple folders in it all the contents of each folder is placed into just the on directory instead of having a multiple folders in the archive.
Thanks,
Tony
This will set the working directory to the folder that you want to zip up and save the zip file one level up from that directory.
#echo off
for /d %%X in (*) do (
PUSHD "%%X"
"D:\Program Files\7-Zip\7z.exe" a "..\%%X.7z" "*"
POPD
)
I have a thousand zip archives that all contain a file I want to remove. I can get 7Zip to remove them one file at a time from the command line:
7z d -r archive.zip *.pdf
but how would I apply that across all the files, which are themselves grouped in sub-directories?
Try this:
for /r %v in (*.zip) do 7z d -r "%v" *.pdf
But no idea if it's working, just wrote out of my head :P
FOR /F "tokens=*" %%G IN ('dir /b *.zip') DO 7z.exe d -r %%G *.pdf
This works almost in the same way as the accepted answer. Only the way how the files are gathered is different. Whereas the answer above uses for /r to run through all directories and subdirectories, this one parses the output of the command dir /b *.zip to get all the files relevant.
The 7zip command remains the same and only the parameters are changed.
Note: To run this outside of a batchfile replace %%G with %G
Sometimes simple things can solve the problems...
do the following to delete any file / all file from selected .zip files>
Move the .zip files to a new folder
Select all the files from which files to be deleted
right click and select option "extract each archive to separate folder"
all the zip files shall be converted to folder now.
use and file search tool like SearchMyFiles and find required files, select and delete.
convert the folders back to .zip
With a batch (.bat), I want to copy all mp3 files that are in 1 subdirectory of D:\TEMP
D:\TEMP\\(anyfolder)\\(anyfile.mp3)
to
E:\MYFOLDER\
I tried with xcopy but
I don't know how to tell "just recurse subfolders of D:\TEMP and not subsubfolders, subsubsubfolders, etc."
When using xcopy, folders are created in the destination (in order to replicate source's folder tree), I don't want this : files should be copied in just 1 single folder.
for command is your friend. Read help for and then try this in the command prompt
for /d %a in (*) do #echo %a
as you see, it follows all subfolders in the current directory.
thus,
for /d %a in (*) do #copy %a\*.mp3 e:\myfolder
will copy all your mp3 to the destination folder.
I have a folder containing many other sub-folders. I am trying to write a batch file which will copy some of the folders to another place on my hard disk. I am using xcopy for this. The folder structure is as shown below:
FolderB1
FolderB2
FolderB22
File1.txt
File2.txt
File3.txt
I have some .txt files inside FolderB1, along with FolderB2 and FolderB22. I want to copy FolderB2 and FolderB22 and skip .txt files contained in Folder B1
I tried using /EXCLUDE: param of xcopy command, but it is not able to perform this operation. It does not work if I specify the exclusion as \FolderB1\*.txt or something of this sort.
The number of main folders is not known. It can be anything. Also, there is no fix pattern for names of .txt files. Have checked this question too, but did not help.
Also, I want to avoid using del command, since copying all and deleting again would consume time.
Can this be achieved using Robocopy? Exactly similar question is raised here.
Any pointers would be useful. Thanks in advance.
To clarify, I asume you mean to exclude all .txt files in FolderB1, but not exclude .txt located elsewhere.
You can do that with robocopy in two steps. First copy all files except any .txt. And in the second step copy only .txt files, but exclude FolderB1.
robocopy c:\source c:\destination /s /xf *.txt
robocopy c:\source c:\destination *.txt /s /xd c:\source\FolderB1