---
title: "Checking NSString path is a Directory or File in iOS."  
description: "Checking NSString path is a Directory or File in iOS."  
author: "Anonymous User"  
published: 2016-01-04  
updated: 2016-01-04  
canonical: https://www.mindstick.com/forum/33829/checking-nsstring-path-is-a-directory-or-file-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# Checking NSString path is a Directory or File in iOS.

In our [iPhone application](https://www.mindstick.com/forum/23139/can-i-embed-a-custom-font-in-an-iphone-application) I have a nsstring which can be a [path](https://www.mindstick.com/articles/44333/4-expert-tips-on-how-to-pick-the-right-career-path) of any [location](https://www.mindstick.com/blog/11636/relocating-business-or-office-to-another-location) or [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp).

Now, I want to [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) that [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp)(path) is locating a file or folder/director.

Is this possible in Cocoa to check the string path for file or [directory](https://www.mindstick.com/forum/226/how-to-get-application-directory-using-c-sharp-csharp), then please provide [me the code](https://www.mindstick.com/forum/156831/can-you-tell-me-the-code-to-write-a-c-sharp-program) or tell me the method.\
Thank you.

## Replies

### Reply by Tarun Kumar

For checking existence of file or directory you can use NSFileManager:\
[[NSFileManager defaultManager]fileExistsAtPath:path_name isDirectory:&directoryFlag];\
Here we are providing complete example:

```
NSString *dirPath = @"/Album/";BOOL check;NSDirectoryEnumerator *enum = [[NSFileManager defaultManager] enumeratorAtPath:dirPath];while((dirPath = [enum nextObject])){   [[NSFileManager defaultManager] fileExistsAtPath:dirPath isDirectory:&check];   if(check){      NSLog(@"Directory Path: %@", dirPath);   }}
```


---

Original Source: https://www.mindstick.com/forum/33829/checking-nsstring-path-is-a-directory-or-file-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
