0

Hey folks I have been stuck into the situation where I wanted to know the File type of few files who has no extension. I know till now that every file is associated with UTI Identifier and Extension.

1. In my case file extension is not available so no questions.

2. File has no extension.

Apple documentation over file system over O.S

One of stack overflow reference

Article over dynamic UTI

I have been here too but guess there is something I am missing or going in the anonymous direction.

Your help must be appreciated.

Community
  • 1
  • 1
Vikram Sinha
  • 581
  • 1
  • 10
  • 25
  • In general, if there's no extension, then you have to guess what the file type is. linux uses `libmagic` to examine the content of the file to try to determine the file type. There is a bsd command `magic` as well - if you run `file --mime-type *` it will try to get a mime-type (e.g. image/png) for all the files in the current directory. – Anya Shenanigans Sep 01 '16 at 13:17
  • @Petesh thanks for the reply... at this moment I am doing the same but I was thinking if I get any opportunity to receive file type by any predefined method. I am able to get UTI of my file in "public.data" but it it is image type and so it should give me "public.image" so that I can validate that it is image type file. so if you have any idea if it is possible to get file type of file without extension exactly. – Vikram Sinha Sep 01 '16 at 13:38
  • By default the UTI will be `public.data` if there's no extension. I'm struggling in understanding what the problem is - you can't conjure a UTI for a file without some examination of the file. There is really no shortcut to this if you don't have an extension to base your expectation on. – Anya Shenanigans Sep 01 '16 at 14:19

2 Answers2

0

UTIs are designed to allow the passing of typed data between applications primarily e.g. the sending of images over the clipboard. As long as the data is tagged with the appropriate UTI, it will be available for consumers who can deal with that type of data.

The application placing the data on the pasteboard is responsible for determining the appropriate UTI(s) that are placed onto the pasteboard.

When you determine the UTI for a file, the operating system gets this from the extension that is used. This is the only source that the operating system uses to determine the UTI when it looks at a file. If there is no extension for the file, it is given the UTI public.data.

Instead, Mac OS X derives the UTI from other information, primarily—and tragically—from the file name extension.

The UTI is not stored/cached/retained in any form on the file system, except in the form of the file's extension.

The only mechanism that is available other than using the file extension is to use a tool like file, or it's library libmagic, that is part of the file program's distribution to interrogate the file to determine it's probable file type.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
-2

you can try this :

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil];
NSString *fileName = @"YOUR_FILE_NAME";
for (NSString *file in directoryContent )
{
    NSString *fileNameWithOutExt= [file stringByDeletingPathExtension];
    if([fileName isEqualToString:fileNameWithOutExt])
    {
        NSLog(@"Found");
    }
}
Return Zero
  • 424
  • 4
  • 15
  • I want to the content type of file pal.. I am not looking for file identical... You can see safari's cache files those have no extension and I just looking for those file's types... – Vikram Sinha Sep 01 '16 at 12:06