Compress a folder using NTFS compression in .NET

前端 未结 6 1241
Happy的楠姐
Happy的楠姐 2021-02-01 09:48

I want to compress a folder using NTFS compression in .NET. I found this post, but it does not work. It throws an exception (\"Invalid Parameter\").

DirectoryI         


        
6条回答
  •  无人共我
    2021-02-01 10:10

    When creating the Win32_Directory.Name=... string you need to double the backslashes, so for example the path C:\Foo\Bar would be built up as:

    Win32_Directory.Name="C:\\Foo\\Bar",

    or using your example code:

    string objPath = "Win32_Directory.Name=\"C:\\\\Foo\\\\Bar\"";

    Apparently the string is fed to some process that expects an escaped form of the path string.

提交回复
热议问题