找到最低的子文件夹并压缩它们
Visual Studio 模板的文件夹结构如下:
/ProjectTemplatesCache
/CSharp
/Windows
/1033
/ClassLibrary.zip -- the lowest subfolder
/Properties
/WindowsService.zip -- the lowest subfolder
/1042
/VisualBasic
我想从根文件夹开始,深入到最低的子文件夹并将每个子文件夹压缩到一个单独的存档中。
使用 Windows 批处理或 C#。
如何压缩 - 并不重要。只需能够单独选择每个/对每个执行命令即可。
有什么想法吗?
Visual Studio Templates has folder structure like this:
/ProjectTemplatesCache
/CSharp
/Windows
/1033
/ClassLibrary.zip -- the lowest subfolder
/Properties
/WindowsService.zip -- the lowest subfolder
/1042
/VisualBasic
I want to start at the root folder, dig down to the lowest subfolders and zip each of them to a separate archive.
Using Windows Batch or C#.
How to zip - doesn't matter. Just be able to select each separately / execute a command against each.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
C# 4.0:
查看 ICSharpZip 进行实际压缩
更新:
好的,只需将条件与
Where()
混合即可您始终可以提供
Func
来决定要压缩哪些目录C# 4.0:
Look at ICSharpZip to do the actual zipping
Update:
Ok, just mixing the condition with the
Where()
you can always provide a
Func<DirectoryInfo, bool>
to decide which directories are toBeZipped如果您使用 C#,则:
...如果您确实想要unzip,请尝试在 .net 中以编程方式解压缩文件
If you are using C# then:
... and if you actually want to unzip, then try Unzip files programmatically in .net
那么,您本质上是想找到所有没有子目录的子目录吗?
当然,如果存在当前用户无权访问的子目录等,就会出现问题,但我感觉这段代码是用于在受控环境中运行的一些便利工具。
So, you essentially want to find all sub directories that in turn has no sub directories?
Of course there will be issues if there are sub directories to which the current user does not have access and such, but I get the feeling that this code is for some convenience tool that will operate in a controlled environment.
下面的代码递归地遍历目录树。您应该能够使用它作为代码的基础:
如果没有更多的目录可以继续下去,您可以只返回一个布尔值,然后压缩所有文件。
This code below recursively goes through a directory tree. You should be able to use it as a basis for your code:
You can just return a bool if there are no more directories to go down and then zip all the files.