processInfo can't get all files in the array, can you help me with this please ?

Discussion in 'iOS Programming' started by master12, Jul 14, 2012.

  1. master12 macrumors newbie

    Joined:
    Mar 21, 2012
    #1
    Code:
    NSProcessInfo *proc = [NSProcessInfo processInfo];
            NSArray *args = [proc arguments];
            NSFileManager *fm = [NSFileManager defaultManager];
            
            if([args count]>1) { NSLog(@"moreThanOne");}
    This is my code and I it doesn't display "moreThanOne" in the terminal, but it should, because I got in the folder "Debug" text-file and the executable file, and also one folder.

    args contains only 1 path to the file and that file is executing file (application)

    Why it doesn't work for me ?

    Thank you
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    The arguments array is a list of process arguments. It's not a list of files in the same folder as the executable.

    The process arguments are exactly the parameters that your C main function receives. Write code that lists the actual values in the arguments array. Do the same in your main function, with the argc and argc parameters.
     
  3. master12 thread starter macrumors newbie

    Joined:
    Mar 21, 2012
    #3
    I'm sorry... I didn't get it all.. Could you please show me which code I should write that lists the actual values in the arguments array ?
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Write a loop that prints every value in the NSArray args. What does it show? Post the output.

    It should show the list args.

    You should then add code in your main function that prints argc and each char* in argv, so you can compare the output with the NSArray output.

    Now, given the output produced by the two loops, how does that have anything to do with listing the contents of the folder where the executable resides?

    You originally wrote:
    Clearly, you think that printing the args (the exercise above) should be the same as listing the contents of the folder where the executable resides. Or you think the arguments must be a list of the contents of that folder.

    Neither of these is correct. The arguments are passed to the process. They aren't automatically set to the contents of the executable's folder.


    To get the contents of a folder, you must do two things:
    1. Get the pathname of a folder.
    2. Use NSFileManager to list its contents.

    If you haven't done 1, you can't do 2.


    If you're learning from a book or tutorial, which one? (Title, author, edition, or tutorial URL.)

    If you're working through an exercise from a book or tutorial, which one? (Chapter, page, exercise number.)
     

Share This Page