Question Creating a Zip-like file

Aurhell

Member
Joined
Sep 18, 2024
Messages
5
Programming Experience
3-5
Hi,

I know that C# / .NET may not be the best language to achieve this, but C# is the language I'm the most familiar with (coding it's just a hobby of mine).

What I mean by "zip-like" is like a "virtual" file, containing subfolders / files, but not compressed.

I'd like to do a Windows' Explorer like.

Ideally I'd like to get a result like this

Main directory : Pictures / Movies / Games / Etc.
Sub directories :
* Pictures - Animal, Art, etc​
* Movie - Action, Comedy, Sci-fi, etc​
* Games - RPG, Shoot'em up, Adventure, etc.​
Of course, I'd also like to remove /edit things, search
My main question is, is that doable ? (Especially in C#) I guess using Windows API could help.

Have a good day !
Aurélien.
 
Yes. It's doable.

No need for direct calls to Windows API. Just use the Framework's Stream class and make up your own file format where you place things in a hierarchy within a single file accessed by our Stream object.

The key part though is making up your own file format and managing it. That is something that you'll have to do on your own. Neither C# nor the framework library has an abstraction that will do this for you.

The GUI that manifests that hierarchy is also going to mostly up to you, but since you posted in the WinForms section, you can use the TreeView and ListView controls to present your data.

Another alternative if you want the framework to do some the hierarchy abstraction for you is just have an object graph in memory and use serialization and deserialization.
 
Alright ! Thank you Skydiver !

I kinda knew that nowadays, with frameworks and modern languages everything can be coded. I just wanted to make sure that it is feasible for someone like me who codes as a past-time.

Thank you very much for your answer.

Best regards !
 
If you don't want to invent your own file storage, you can use Microsoft's. MS used to use this file format for the older .DOC, .XLS, .PPT, files before Office 2007. It's part of the Windows COM APIs, and someone wrote a library to make it easier to access that data using C#. (Looks like it doesn't even using the Windows COM API -- it does it all on its own.)

 
Thank you for sending this useful link !

I'll surely spend time into creating my own file storage, but later. I'm the kind of person who prefers having something working at first. Then, improving it.

Thank you very much for your help and links ! Both are very much appreciated !

Also, even reading code is interesting.

May I ask your thoughts about Visual Studio vs Resharper ? ;)
 
MS used to use this file format
And they still do, when I was looking into the format of solution (.sln) and project files, I found that active configuration was stored in a .suo file (in hidden .vs subfolder) in structured storage format.
 
What you're actually talking about is creating a filesystem, not a file

What's the end goal? I ask because I wonder if you might as well just look for something that lets you access some existing "file that is a filesystem" like a virtual machine hard disk or an iso file

Maybe go ask chat gpt for recommendations on c# libraries that can manipulate virtual machine hard disk files or iso files
 
Hi,

You are correct cjard.

I guess I could also just handle the files with an XML file.

Okay I want to have main directory, which contains subdirectories and files.

Basically, a Treeview which would be populating after reading the XML file would look like this :
  • Videos
    • Anime
    • Movies
    • Shows
  • Music
    • Classic
    • Hip Hop
    • Metal
  • Games
  • Pictures
  • Etc.....
Or maybe, even creating an user control that inherits from a Treeview and add / overwrite methods that fit my expections.

This looks like more easier to me. What are your thoughts about this ?

Have a good day.
Aurélien.
 

Latest posts

Back
Top Bottom