LoginSignup
2
2

More than 5 years have passed since last update.

Objective-C フルパスから親ディレクトリ・ファイル名取得

Last updated at Posted at 2017-11-24

例えば、下記のフルパスがあり、
/User/HogeHoge/Documents/test.png

親ディレクトリやファイル名だけの文字列を取りたい場合は、
以下のコードで取得出来る。

親ディレクトリ取得

Objective-C
NSString *path = @"/User/HogeHoge/Documents/test.png";
NSString *str = [path stringByDeletingLastPathComponent];
NSLog(@"%@", str);
出力
/User/HogeHoge/Documents

ファイル名取得

Objective-C
NSString *path = @"/User/HogeHoge/Documents/test.png";
NSString *str = [path lastPathComponent];
NSLog(@"%@", str);
出力
test.png
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2