Skip to content

Instantly share code, notes, and snippets.

@vbfox
Created August 21, 2014 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbfox/36f0c323b76b91e94697 to your computer and use it in GitHub Desktop.
Save vbfox/36f0c323b76b91e94697 to your computer and use it in GitHub Desktop.
Call 7-Zip from a FAKE F# script
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