How to create a rar file with every file matching a pattern (including subdirectories) on Windows


November 2013.

Creating the rar file


How to create a rar file with any file matching a pattern (including subdirectories) on Windows.


forfiles /s /m wallet.dat /c "cmd /c echo @relpath" | "c:\Program Files\WinRAR\Rar.exe" a -dh -rr524288 wallets.rar @

RAR 4.20 Copyright (c) 1993-2012 Alexander Roshal 9 Jun 2012
Registered to zewaren

Updating archive wallets.rar

Updating .\Alphacoin\wallet.dat OK
Updating .\AmericanCoin\wallet.dat OK
Updating .\AndroidsToken\wallet.dat OK
Updating .\Betacoin\wallet.dat OK
Updating .\Bitcoin\wallet.dat OK
Updating .\Colossuscoin\wallet.dat OK
Updating .\digitalcoin\wallet.dat OK
Updating .\eMark\wallet.dat OK
Updating .\Fastcoin\wallet.dat OK
Updating .\Feathercoin\wallet.dat OK
Updating .\Florincoin\wallet.dat OK
Updating .\Franko\wallet.dat OK
Updating .\Gridcoin\wallet.dat OK
Updating .\IncaKoin\wallet.dat OK
Updating .\Litecoin\wallet.dat OK
Updating .\Luckycoin\wallet.dat OK
Updating .\Namecoin\wallet.dat OK
Updating .\NetCoin\wallet.dat OK
Updating .\NovaCoin\wallet.dat OK
Updating .\Ocoin\wallet.dat OK
Updating .\Phoenixcoin\wallet.dat OK
Updating .\PPCoin\wallet.dat OK
Updating .\Primecoin\wallet.dat OK
Updating .\Protoshares\wallet.dat OK
Updating .\Redcoin\wallet.dat OK
Updating .\RoyalCoin\wallet.dat OK
Updating .\Terracoin\wallet.dat OK
Updating .\Worldcoin\wallet.dat OK
Updating .\YaCoin\wallet.dat OK
Updating .\Sexcoin\wallet.dat OK
Done

This example will find any file named wallet.dat and include it in the rar file. You can use wildchars in the pattern.

This will preserve the directory structure.

-dh allows you to add files that are in use by another process.

-rr524288 adds a recovery record to the archive, with the maximum number of sectors (never too cautious).

Checking the rar file



"c:\Program Files\WinRAR\Rar.exe" vb wallets.rar
Alphacoin\wallet.dat
AmericanCoin\wallet.dat
AndroidsToken\wallet.dat
Betacoin\wallet.dat
Bitcoin\wallet.dat
Colossuscoin\wallet.dat
digitalcoin\wallet.dat
eMark\wallet.dat
Fastcoin\wallet.dat
Feathercoin\wallet.dat
Florincoin\wallet.dat
Franko\wallet.dat
Gridcoin\wallet.dat
IncaKoin\wallet.dat
Litecoin\wallet.dat
Luckycoin\wallet.dat
Namecoin\wallet.dat
NetCoin\wallet.dat
NovaCoin\wallet.dat
Ocoin\wallet.dat
Phoenixcoin\wallet.dat
PPCoin\wallet.dat
Primecoin\wallet.dat
Protoshares\wallet.dat
Redcoin\wallet.dat
RoyalCoin\wallet.dat
Terracoin\wallet.dat
Worldcoin\wallet.dat
YaCoin\wallet.dat
Sexcoin\wallet.dat

Image