Skip to main content

Create a batch file to archive all subfolder in the folder d:\MyData and move it to d:\MyDataArchvies using winrar archive tool

 To create a batch file to archive all subfolders in the folder d:\MyData and move it to d:\MyDataArchives using the winrar archive tool, you can use the following steps:

  1. Open a text editor, such as Notepad, and type the following commands:
@echo off

for /d %%a in ("d:\MyData\*") do (
    "C:\Program Files\WinRAR\Rar.exe" a -ep1 -r -df -inul "d:\MyDataArchives\%%~na.rar" "%%a"
)


  1. Save the file as archive-mydata.bat in the folder d:\MyData.

  2. To run the batch file, double-click on it or open a command prompt and navigate to the d:\MyData folder and type archive-mydata.bat. This will create a .rar archive file for each subfolder in the d:\MyData folder and move it to the d:\MyDataArchives folder.

Note: The above instructions assume that the winrar executable is installed in the default location (C:\Program Files\WinRAR\Rar.exe). If it is installed in a different location, you will need to update the path in the batch file accordingly. Additionally, the -ep1 and -inul flags in the Rar.exe command are used to exclude the parent directory and prevent displaying any messages during the archiving process.

Comments