Created
June 16, 2014 19:08
-
-
Save saurabhwahile/50f1091fb29c2bb327b7 to your computer and use it in GitHub Desktop.
Creating RAR Archives From Windows Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Set-ExecutionPolicy Unrestricted | |
$fromFolderPath = $args[0][0] | |
$toFolderPath = $args[0][1] | |
$toFilename = "" | |
if ($fromFolderPath.Split("\")[-1] -eq "") | |
{ | |
$toFilename = $fromFolderPath.Split("\")[-2] | |
$fromFolderPath = $fromFolderPath.SubString(0, ($fromFolderPath.length-1)) | |
} | |
else | |
{ | |
$toFilename = $fromFolderPath.Split("\")[-1] | |
} | |
$toFilePath = $($toFolderPath+"\"+$toFilename+".rar") | |
#Keep backup if archiving fails | |
try | |
{ | |
move $toFilePath $($toFilePath+".old" ) | |
} | |
catch | |
{ | |
echo "No Backup Found" | |
} | |
#Generate RAR archive | |
$argList = @("a", ('"'+$toFilePath+'"'), ('"'+$fromFolderPath+'"')) | |
Start-Process -FilePath "C:\Program Files\Winrar\winrar.exe" -ArgumentList $argList -NoNewWindow -Wait | |
#Remove Backup | |
$toFilePathOld = ($toFilePath)+".old" | |
del $toFilePathOld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$fromFolder = $currentPath.Substring(0, ($currentPath.length-1)) | |
$toFolder = ($env:USERPROFILE+"\Desktop\Backup") | |
$argList = @($PWD.Path, $toFolder) | |
& ($env:PS_SCRIPTS+"\backup-winrar.ps1") $argList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment