I am really new to batch files so please bear with me. I want to make a batch file that can zip folders inside the main folder to one individual win-rar file.
I have the following line which is making the main folder rar but i need only the folders inside the main folder to be archived.
SET WINRAR="F:\Program Files\WinRAR"
%WINRAR%\WinRAR.exe a -ep1 "F:\Documents and Settings\sys\Desktop\test.rar" "F:\Documents and Settings\sys\Desktop\test"
What I need is to make the folders inside the test folder as individual rar files.
Iterate over the folders to create individual rar files
SET WINRAR="F:\Program Files\WinRAR"
for /D %%f in ("F:\Documents and Settings\sys\Desktop\test\*") do (
%WINRAR%\RAR.exe a -ep1 -r0 "F:\Documents and Settings\sys\Desktop\test\%%~nxf.rar" "%%f"
)
Related
I saw the other links for some solutions but, I need to run the script for every folder under a main one but to give it its original name.
Example:
Main folder
Folder 1
Folder 2
Folder 3
To output (in the same main folder)
Main folder
Folder 1.zip
Folder 2.zip
Folder 3.zip
Thank you in advanced
You'll need zipjs.bat in the same directory as this piece of code:
#echo off
::Alter the line bellow with your parent directory
set "parent_dir=C:\Parrent\"
for /d %%a in ("%parent_dir%\*") do (
call zipjs.bat zipItem -source "%%~fa" -destination "%%~fa.zip" -keep yes -force no
)
I have found a simple solution for this. Suppose you have multiple sub folders to be zipped in a folder. In that case,
1. Download and lnstall 7zip software. Then copy 7z.exe to the particular folder where you want to zip your subfolders.
in a notepad, copy and paste the following and save as .bat file. :
cd "your_MainFolder_path"
for /d %%f in do (7z a -t7z %%f.7z "your_mainFolder_path\%%f")
In case you want to keep the zip files and remove the original folders, add this after the for statement :
rd /s /q "your_mainFolder_path\%%f"
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
)
Using the WinRAR command line (C:\Program Files\WinRAR\Rar.exe), what I'm trying to do is compress a single folder in a main folder (C:\Users\%username%\desktop\mainFolder) to a new folder (C:\Users\%username%\desktop\newFolder) and delete the single folder after compression in the main folder.
So that ONLY the first subfolder is compressed every time I start the .bat
C:\Users\%username%\mainFolder
singleFolder1
singleFolder2
singleFolder3
So far that does only work for all folders which are in the main folder
c:
cd \Users\%username%\Desktop\newFolder
"C:\Program Files\WinRAR\Rar.exe" a -ep1 -mt5 -m1 -v50M -r "!_RndAlphaNum!" C:\Users\%username%\Desktop\mainFolder\
The !_RndAlphaNum! is because I use a code at batch start that generates random names for the .rar archives.
That is similar to Using a loop to rar multiple subfolders in a main folder and can be therefore easily achieved with
#echo off
for /D %%F in ("%USERPROFILE%\mainFolder\*") do (
"%ProgramFiles%\WinRAR\Rar.exe" m -ep1 -mt5 -m1 -v50M -r "%USERPROFILE%\desktop\newFolder\%_RndAlphaNum%" "%%~F"
goto Done
)
:Done
The command goto Done results in breaking FOR loop after processing first directory and continue the batch job below label Done.
Again command m is used instead of a to archive and then delete all files and folders packed into the archive file created directly in the destination folder.
I have a folder with many subfolders inside them, the subfolders have random numbers/characters as their name, and they all do have an important file in them. But how do i copy all the files in the source folder and in the subfolders to one folder without copy the folders, in a batchfile?
I use Windows7
This should be all you need.
#echo off
for /r "d:\base\folder" %%a in (*) do copy "%%a" "c:\destination\folder"
In a folder, I have some folders. I want to compress all the folders separately to the foldername.rar and delete the original files. I want to perform this function in batch.
I tried the ones given in other answers but they only compress the files if present, or do nothing. Here , I have to compress only folders to their respective archive. Please help
WinRAR includes two command-line tools, rar.exe and unrar.exe, where rar.exe compresses and unrar.exe uncompresses files.
Both are located in the “C:\Program Files\WinRAR” folder in the installable version.
Assuming, if there are multiple folders under D:\test and you want each folder to get its own .rar file , in the parent folder, from a batch file, this works for you:
#echo off
setlocal
set zip="C:\Program Files\WinRAR\rar.exe" a -r -u -df
dir D:\test /ad /s /b > D:\test\folders.txt
for /f %%f in (D:\test\folders.txt) do if not exist D:\test\%%~nf.rar %zip% D:\test \%%~nf.rar %%f
endlocal
exit
Explanation....
It'll create .rar files of all the folders/subfolders under parent folder D:\test in the same parent folder.
Then, it'll delete all the original folders/subfolders under parent folder D:\test and thus you'll be left only with the archives at the same place.
“a” command adds to the archive
“-r” switch recurses subfolders
“-u” switch. Equivalent to the “u” command when combined with the “a” command. Adds new files and updates older versions of the files already in the archive
“-df” switch deletes files after they are moved to the archive
Maybe something like this, change C:\testfolder\ to you liking.
In my example I had 3 folders (with random files and subfolders inside em): one, two and three
#echo off
cd "C:\testfolder\"
for /d %%G in ("*") do (
"%programfiles%\WinRAR\Rar.exe" a -r %%G.rar %%G
rd /s /q %%G
)