Is it possible to identify all types of compressed (.zip, .7z, .rar, etc) files in c#.
I know that can be done by identifying file extension but is that the reliable way or is there any better way to do so?
Is it possible to identify all types of compressed (.zip, .7z, .rar, etc) files in c#.
I know that can be done by identifying file extension but is that the reliable way or is there any better way to do so?
You can try the below code (I did not try)
//YOUR FILE
FileAttributes attributes = File.GetAttributes("c:/Temp/SomeFile");
//CHECK FOR COMPRESSED
if ((attributes & FileAttributes.Compressed) == FileAttributes.Compressed)
{
Console.WriteLine("The file is compressed.");
}
Reading:
https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributes?view=netframework-4.8