我在學習Objective-C
,並且正在將Applescript實用程序轉換爲Objective-C
。如何獲取目標文件的創建日期目標c
我需要了解如何獲取目錄中所有文件的NSFileCreationDate
,以便我可以將最新的文件複製到其他位置。我不知道如何獲取目錄中每個文件的NSFileCreationDate
。
此代碼獲取目錄的列表,但每次我嘗試獲取NSFileCreationDate
時,它都給出了包含文件夾的NSFileCreationDate
。
我必須閱讀plist文件以獲取備份位置的路徑。對於備份位置
- 讀取plist文件
- 獲取創建文件的日期
複製的最新文件* wholepath,在桌面上的文件
的NSString 文件路徑= [@「〜/資源庫/ Preferences/com.viive.Viive.plist「stringByExpandingTildeInPath」; NSMutableDictionary plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
NSString *value; value = [plistDict objectForKey:@"backupPath"]; NSFileManager *filemgr; NSArray *filelist; filemgr = [NSFileManager defaultManager]; filelist = [filemgr contentsOfDirectoryAtPath:value error: nil]; NSArray *array = filelist; NSUInteger index = 0; for (id element in array) { NSLog(@"Element at index %lu is: %@", (unsigned long)index, element); index++; } NSDictionary* fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath://// error:nil]; NSDate *result = [fileAttribs fileCreationDate]; //or fileModificationDate NSLog(@"%@",result); ////// NSString* desktop = [@"~/Desktop/LOGS-I-NEED-" stringByExpandingTildeInPath]; NSString* computername = [[NSHost currentHost] localizedName]; NSString* wholepath = [desktop stringByAppendingString:computername];
我GOOGLE了這個信息,因爲我是新來的這個我發現不作出了很多的意義,我的答案。如果有人知道更好的方式,我全都耳熟能詳。
謝謝大家!
此代碼給我 - [__ NSCFString路徑]:無法識別的選擇發送到實例0x106107c30 – Breathable
出現在代碼中的錯誤。請再試一次。 – Max
我得到(空)然後,如果我再試一次我得到的文件內容的列表,但然後我得到這個*** - [__ NSArrayM objectAtIndex:]:索引34超越邊界[0 .. 33] – Breathable