how to get URL Path for directory inside Document directory?

前端 未结 4 1106
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-19 10:53

How can I get url path for a particular directory inside Document Directory.

like Document/Art/

My code

- (NSURL *)localRoot {
         


        
相关标签:
4条回答
  • 2021-01-19 11:05

    Application.StartupPath;

    is used to find your path where your application is being started, if that is what you mean.

    0 讨论(0)
  • 2021-01-19 11:10
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    NSString *yourArtPath = [documentsDirectory stringByAppendingPathComponent:@"/Art"];
    
    0 讨论(0)
  • 2021-01-19 11:19

    Based on above answer here is an simple methode that returns, path for given directory:

    + (NSString *) pathFor : (NSString *) directoryName{
        return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:directoryName];
    }
    

    You need to implement it in ClassName.m and call as:

    NSString *pathForDirectory = [ClassName pathFor:dirName]; //@"Art" in your case
    
    0 讨论(0)
  • 2021-01-19 11:22

    Use this

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    NSString *appFile_a = [documentsDirectory stringByAppendingPathComponent:@"/Art"];
    
    0 讨论(0)
提交回复
热议问题