nsfilemanager

How to detect if a file was closed?

独自空忆成欢 提交于 2019-12-24 15:55:20
问题 is it possible to detect if a file (e.g. a pdf file opened in preview) was closed? The FSEvents API does not fire such an event. Maybe I could observe the associated process or something like that?! 回答1: Yes there is the way that you can find out whether file has been closed or not. So below i tried with unix lsof -t yourFilePath command to determine the same and hence have implemented the same in cocoa. Please follow below here lsof -t yourFilePath will give you the process id of only open

How do I count a number of images in a folder reference in swift

懵懂的女人 提交于 2019-12-24 03:18:45
问题 I'm working on an custom emoji keyboard in Swift and I'm having trouble finding and counting the images in a folder reference called "emojis". EDIT: To clarify my issue is that let contents always end up as nil. The structure from the location of the .xcodeproj file looks like this: EmojiBoard/emojis/emoji-0.png and so on. I've been trying to use the NSFileManager with no luck. let fileManager = NSFileManager.defaultManager() let contents = fileManager.contentsOfDirectoryAtPath("emojis",

NSFileManager URL vs Path

牧云@^-^@ 提交于 2019-12-23 13:01:58
问题 Why is that URL methods like moveItemAtURL:toURL:error: of NSFileManager class are recommended over Path methods like moveItemAtPath:toPath:error: ? 回答1: When NSURL objects are created it's also checked that the path is valid, otherwise the object is not created. The path ones are created even if it's an invalid path. There are no checks made at all. 来源: https://stackoverflow.com/questions/30023679/nsfilemanager-url-vs-path

Error copying files with FileManager (CFURLCopyResourcePropertyForKey failed because it was passed an URL which has no scheme)

假如想象 提交于 2019-12-23 07:21:58
问题 I'm trying to copy some (media) files from one folder to another using FileManager 's copyItem(at:path:) , but I'm getting the error: CFURLCopyResourcePropertyForKey failed because it was passed an URL which has no scheme Error Domain=NSCocoaErrorDomain Code=262 "The file couldn’t be opened because the specified URL type isn’t supported." I'm using Xcode 9 beta and Swift 4. let fileManager = FileManager.default let allowedMediaFiles = ["mp4", "avi"] func isMediaFile(_ file: URL) -> Bool {

Error copying files with FileManager (CFURLCopyResourcePropertyForKey failed because it was passed an URL which has no scheme)

我的未来我决定 提交于 2019-12-23 07:21:11
问题 I'm trying to copy some (media) files from one folder to another using FileManager 's copyItem(at:path:) , but I'm getting the error: CFURLCopyResourcePropertyForKey failed because it was passed an URL which has no scheme Error Domain=NSCocoaErrorDomain Code=262 "The file couldn’t be opened because the specified URL type isn’t supported." I'm using Xcode 9 beta and Swift 4. let fileManager = FileManager.default let allowedMediaFiles = ["mp4", "avi"] func isMediaFile(_ file: URL) -> Bool {

What is the hexadecimal part in the Documents folder's path?

百般思念 提交于 2019-12-23 02:48:10
问题 I have a file located in my app's Documents folder. When the app is terminated I save the file's URL in the AppDelegate's applicationWillTerminate method: // archiver init code [archiver encodeObject:file.URL forKey:kFileURL]; // finish encoding and write data to file system But when trying to restore the file on the next app launch the file manager cannot locate the file: After calling NSURL *fileURL = [unarchiver decodeObjectForKey:kFileURL]; NSString *filePath = fileURL.path; the method [

How to get all the names of photos only which are saved in documents folder of iphone application

≡放荡痞女 提交于 2019-12-23 01:36:20
问题 i want to get all the photos names saved in my documents folder .as it contains some resources other than images,i need to select the images itelf from the documents folder and populate the names of images in an array. 回答1: NSString *documentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDir error:nil]; NSArray *onlyPics = [dirContents

update progress bar during copy file with NSFileManager

拈花ヽ惹草 提交于 2019-12-22 17:19:07
问题 I copy files then my application is finish launching from resource to caches directory. but I want to update my progress bar during copying the files. I copy the file with the code below: -(BOOL)copyDirectory:(NSString*)source toDirectory:(NSString*)targat { BOOL retVal = YES; NSFileManager *fileManager = [[NSFileManager alloc] init]; NSError *error; if ([fileManager fileExistsAtPath:targat] == YES) { NSError *error = nil; [fileManager removeItemAtPath:targat error:&error]; } if(![fileManager

replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error: broken in iOS 6?

柔情痞子 提交于 2019-12-22 17:06:39
问题 I cannot get the NSFileManager method replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error: to work in iOS 6. Apps that call this method and worked fine on iOS 5 have major issues on iOS 6. The problem does not occur on devices running versions of iOS below 6.0. The problem does not occur if the app is launched in the iOS Simulator by Xcode. Otherwise the problem seems to be universal. Here is the test code I am trying to execute: NSError *error; NSFileManager

fileManager.createFileAtPath always fails

偶尔善良 提交于 2019-12-22 11:30:34
问题 I try to call the fileManager.createFileAtPath -method, but it always fails. My variable success is always false . I looked at some similar posts here but nothing fits my needs exactly. Here is my code: pListPath = NSURL(fileURLWithPath: String(reportsPath)).URLByAppendingPathComponent("myReports.plist", isDirectory: false) let data: NSData = NSData() var isDir: ObjCBool = false if fileManager.fileExistsAtPath(String(pListPath), isDirectory: &isDir) { print("File already exists") } else { let