2012-09-06 66 views
0

我想看一個文件夾,然後將different extensioned & same filenamed文件複製到另一個目錄/文件夾。但我檢查文件與NSFileManager copyItemAtPath toPath

if([myManager fileExistsAtPath:[(NSURL*)pathSource path]]==YES

檢測,返回YES,有文件中directory.But從不復制任何視頻音頻txt文件與

[myManager copyItemAtPath:@"/Users/.../CONTENTS/002BJ" toPath:@"/Users/.../CONTENTS/AUDIO/"; error:nil]

代碼。那麼,我的錯在哪裏?還有其他方法可以將文件複製/移動到目錄嗎?

+0

我也試過用的DestinationPath文件名,但沒有行動,沒有複製 –

回答

1

When a file is being copied, the destination path must end in a filename—there is no implicit adoption of the source filename.

NSString *path = @"/Users/.../CONTENTS/002BJ"; 
[myManager copyItemAtPath:path toPath:[@"/Users/.../CONTENTS/AUDIO/" stringByAppendingPathComponent:[path lastPathComponent] error:nil]; 
+0

謝謝Parag,現在的NSFileManager可能不迴應 '-copyItemAtPath:toPath:stringByAppendingPathCompanent ::錯誤':(( –

+0

NSError *錯誤; [[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:[destinationPath stringByAppendingPathComponent:[sourcePath lastPathComponent]] error:&error]; –

+0

YESSS,非常感謝如果你讓我再問一個問題,我必須輸入擴展名?現在這是我的問題,因爲我有不同的文件,如a.xml和a.txt和a.BMP –