Amazon.com Widgets File doesn't exist?
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2013, 11:20:29 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  Chapter 16
| | |-+  File doesn't exist?
Pages: [1]   Go Down
Print
Author Topic: File doesn't exist?  (Read 661 times)
seerex
Full Member
***
Posts: 177


Email




« on: March 15, 2012, 05:34:32 AM »

Hi,

I'm trying to get the hang of this whole file and directory thingy. I tried the first example with the testfile, but it claims it doesnt exist? i created it in Xcode, and the names of the fn string containing the pathname also reads "testfile", so what could be wrong here? anyone else having this issue? do i maybe need to have the pathname to more than just the file name (if it's included and created in Xcode?)

i tried getting the current directory name, and i get this weird stuff: /Users/seerexis/Library/Developer/Xcode/DerivedData/working_with_files-coscyjkucstvccbylizivsnmsgjk/Build/Products/Debug

and the test file is in the projects group files (along with the header files). I also tried moving it out of the group folders and placing it next to the executable, and i also tried to create a pathname into the folder's map, but haven't succeeded in anything yet. This whole path thing must be confusing me somehow, or i made some sort of mistake. Anyways, the program manages to run this:

Code: (Objective-C)
        NSString *fName = @"testfile";
        NSFileManager *fm;
        NSDictionary *attr;
       
        // Need to create instance of the file manager
        fm = [NSFileManager defaultManager];
       
        // Check directory path
        NSLog(@"%@", [fm currentDirectoryPath]);
       
        // Let's make sure our test file exists first
       
        if ([fm fileExistsAtPath: fName] == NO) {
            NSLog(@"File doesn't exist!");
            return 1;
        }

Thanks on advance
« Last Edit: March 15, 2012, 08:40:25 AM by seerex » Logged

Best Regards -
J.B.J
If you think i helped you could return the favor Wink

Subscribe to my channel on youtube: http://www.youtube.com/user/JBJProgramming

My apps:
- iTap Fruits (all countries)
- Toilet-Quiz (Denmark only)
- Zoo Kids (Denmark only)
- Diablo Item Database (All countries)
skochan
Administrator
Hero Member
*****
Posts: 3106







« Reply #1 on: March 15, 2012, 07:57:19 PM »

Try a full path to the file, such as /Users/steve/Desktop/testfile.   That would be the path the file on the user steve's desktop.  A full path is unambiguous.  You can type the path into Terminal to verify that it's correct.  You can also drag the file into Terminal to see it's path name.

Cheers,

Steve
Logged
seerex
Full Member
***
Posts: 177


Email




« Reply #2 on: March 16, 2012, 04:15:29 AM »

Hi,

The drag-and-drop as the filename path worked, so the program now compiled truly. However, i now have another question in regards to the problem.

The program should, to my understanding, copy the file to a new path (which is just a new directory thing, yes?) and then it tests if the 2 files are equal, which they are since it's a copy. Then it renames the file.

Well, after the program is compiled and done with, i still just have the same old testfile, no testfile2 or any change in the place it is stored on my hard drive. Now, something must have happened, as i am not able to run the program again, since it fails. So what exactly happens? i'm sorry if it is all covered in the book, but i'm a little confused at this point.

I'm thinking it has something to do with a directory not really being the same as an ordinary file or something? or maybe it all happens in the buffer, which i think is a virtual storing place that is not accessible by anything else than the program which contains pointers and stuff to it.

Some clarification would be lovely, a little stumbled on all these concepts  Smiley

Thanks
« Last Edit: March 16, 2012, 04:29:09 AM by seerex » Logged

Best Regards -
J.B.J
If you think i helped you could return the favor Wink

Subscribe to my channel on youtube: http://www.youtube.com/user/JBJProgramming

My apps:
- iTap Fruits (all countries)
- Toilet-Quiz (Denmark only)
- Zoo Kids (Denmark only)
- Diablo Item Database (All countries)
flatlander
Newbie
*
Posts: 4






« Reply #3 on: March 16, 2012, 08:32:58 AM »

I'm having the same issue with test file not found, just done the drag and drop trick in terminal which worked but I get an interesting warning in Xcode: hope tyne screen shot shows up.

anyway it's on about spaces in html i think "%20", now whether that's down to copy and paste? not sure.
But i had tried the usual hardcoded entries which i know work from many years using terminal e.g.. /Users/d/Documents/testfile and ~/Documents/testfile and the program still said file doesn't exist.
Logged
starryVere
Newbie
*
Posts: 6






« Reply #4 on: March 28, 2013, 09:02:04 AM »

flatlander, I know your post was almost a year ago now, but I encountered the same problem and was able to fix it simply by removing the "\" - backward slashes in my pathname. It seems that if your file name has a space in it, that space will get translated into a "\" for some reason. The error results I think because Xcode mistranslates the backward slashes.

Hope that helps somebody reading this thread.
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.