Glenn Smith
Glenn Smith

Reputation: 912

Copy a file from /file to /folder/file

I have been working on an app for a while now, and it is supposed to copy files. I have the code:

- (IBAction)moveFile:(id)sender
{
  NSFileManager *filemgr;
  filemgr = [NSFileManager defaultManager];
  NSString *fileToMove = [NSString stringWithFormat:@"%@", "TestText.txt"];
  if ([filemgr copyItemAtPath: fileToMove toPath: @"./Test/File.txt" error: NULL]  == YES) {
    NSLog (@"Copy successful");
  } else {
    NSLog (@"Copy failed");
  }
}

As you can see, it is supposed to copy the file TestText.txt to the folder /Test/ and rename it File.txt When I activate it, the button clicks, and nothing happens.

Can anyone tell me how to make it work?

Thanks!

Upvotes: 2

Views: 4918

Answers (2)

Glenn Smith
Glenn Smith

Reputation: 912

I fixed it. Did some code-crunching, think it was the "./....." part.

Upvotes: 0

neoneye
neoneye

Reputation: 52161

You have forgotten a @ before "TestText.txt".

Upvotes: 2

Related Questions