How to determine which path my application starts from?

I am creating a small program to copy a domain file for iWeb to a USB drive or an external hard drive or such. The program is designed to run from this USB-drive or external hard drive, and then create the directory from which the application is running. For instance. the application starts from ~ / Documents, the application must create a folder on the website ~ / Documents / (account name), and then copy the domain file to this folder. But when I try to run the application from a USB drive, it creates a folder under / called / (account name). How to fix it?

+3
source share
2 answers

If you need the current working directory of your application, use NSFileManager currentDirectoryPath.

NSString *currentPath = [[NSFileManager defaultManager] currentDirectoryPath];
+4
source

NSBundlehas an instance method called bundlePaththat will almost give you what you want.

NSString *bundleParentPath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];

This should return the directory from which the application is running.

+1
source

Source: https://habr.com/ru/post/1761678/


All Articles