Created
August 21, 2014 08:07
-
-
Save vbfox/36f0c323b76b91e94697 to your computer and use it in GitHub Desktop.
Call 7-Zip from a FAKE F# script
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
let private encodeParameterArgument original = | |
if String.IsNullOrEmpty(original) then | |
original | |
else | |
let temp = Regex.Replace(original, @"(\\*)" + "\"", @"$1\$0"); | |
Regex.Replace(temp, @"^(.*\s.*?)(\\*)$", "\"$1$2$2\""); | |
let private encodeParameterArguments (arguments:seq<string>) = | |
String.Join(" ", arguments |> Seq.map encodeParameterArgument) | |
let private Zip7 (workingDir:string) (fileName:string) (files:seq<string>) = | |
let fullWorkingDir = Path.GetFullPath workingDir + "\\" | |
let correctFileName = | |
files | |
|> Seq.map (fun s -> | |
tracefn "%s -> %s" s fullWorkingDir | |
if s.StartsWith(fullWorkingDir, StringComparison.OrdinalIgnoreCase) then | |
s.Substring(fullWorkingDir.Length) | |
else | |
s | |
) | |
|> Seq.distinct | |
|> encodeParameterArguments | |
let arguments = sprintf "a -tzip -mmt8 %s %s" (encodeParameterArgument fileName) correctFileName | |
tracefn "%s" arguments | |
executeInDir "C:\Program Files\7-Zip\7z.exe" arguments fullWorkingDir true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment