如何创建一个包含文件和目录的文件? [英] How to create a file containing files and directories?

查看:131
本文介绍了如何创建一个包含文件和目录的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WPF 开源Markdown编辑器,现在我需要保存和加载文档.

I am working on a WPF open source markdown editor and I am at the point where I need to save and load documents.

文档"包含3个文件:

  • 用于元数据的XML文件
  • 降价文字的MD文件
  • 用于文档的HTML视图的HTML文件.

在测试时,我为每个文档创建一个目录来保存这些文件,但这不是很方便.我需要将所有这些文件打包在一个文件中,这样用户才不会与3个单独的文件混淆.

At this point for testing I create a directory for each document to hold these files, however this is not very convenient. I need all those files to be packaged inside a single file so users wouldn't be confused with 3 separate files.

我做了一些研究,发现办公室文档具有相似的结构,其中每个文件实际上是一个包含多个目录和文件的软件包.要打开这样的Office文档,您只需要将扩展​​名更改为ZIP,就可以浏览文件,但是在外部,它看起来像是一个文件.

I did a bit of research and found out office documents have a similar structure where each file is actually a package that holds multiple directories and files. To open such an office document all you need to do change the extension to ZIP and you can browse the files, but on the outside it looks as a single file.

我最初的想法是将所有文件压缩为一个文件,在保存时更改扩展名.并在我实际加载文件时将其解压缩.但是我觉得这种方法不是很优雅.

My initial idea was to zip all the files to a single file, change extension when saving. And unzip it when I am actually loading the file. But I felt this approach was not very elegant.

是否有任何优雅的方法将多个文件和目录归档到单个文件中并访问它们,而我在C#中需要它们?

Is there any elegant way to archive multiple files and directories into a single file and access them I need them in C#?

任何建议将不胜感激.

推荐答案

您正确地考虑压缩文件(您不想重新发明轮子),并且正确地解压缩到文件系统也很正确.但是你不必您可以使用自己的代码创建zip文件并将其完全拉出文件

You were right to consider zipping the files (you don't want to reinvent that wheel), and you were also right that unzipping to the filesystem is ugly. But you don't have to; you can create the zip and pull files out of it entirely in your own code with the ZipArchive class.

这篇关于如何创建一个包含文件和目录的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆