Test Zip files in a UNC path using 7za

1.5k views Asked by At

Here is my code:

        string prova = @"\\10.20.9.1\fold\BCK_Capriata\";
        var process = new System.Diagnostics.Process();
        var startInfo = new System.Diagnostics.ProcessStartInfo
        {
            WorkingDirectory = prova,
            WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
            FileName = "cmd.exe",
            RedirectStandardInput = true,
            UseShellExecute = false 
        };
        startInfo.EnvironmentVariables["Path"] = @"C:\Program Files\7-Zip";
        process.StartInfo = startInfo;
        process.Start();
        process.StandardInput.WriteLine("7z t *.7z");
        process.WaitForExit();
        Console.ReadLine();

I get this error:

CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Window directory.

How can I solve this?

EDIT: I understand that I can't start a process in a UNC path and it's better to use directly 7za.exe But now my question is: How can I tell to 7za that I want to test zip in the UNC folder?

1

There are 1 answers

2
Maritim On

Run 7z directly rather than trying to invoke it through cmd. As you can see cmd cannot start with UNC paths as the current working directory.