How do I execute a (rm -R) command by the tap of a button? Code?

Discussion in 'iOS Development' started by ChronicFunk, Aug 9, 2009.

  1. ChronicFunk

    ChronicFunk New Member

    Joined:
    Mar 14, 2009
    Messages:
    289
    Likes Received:
    0
    Device:
    iPhone 4 (Black)
    I need to execute a rm -R /path/to when a button is pressed. I've tried everything I could find on Google and my last resort is to get some feedback from SkylarEC or any other knowlegable developer at iPTFs.

    Can anyone give me any answers?

    Thanks.
  2. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    Code:
    - (void)doCommand {
    [B]   system("rm -R /path/to/whatever/");
    [/B]}
    
    Someone please correct me if I am wrong.
  3. ChronicFunk

    ChronicFunk New Member

    Joined:
    Mar 14, 2009
    Messages:
    289
    Likes Received:
    0
    Device:
    iPhone 4 (Black)
    I have to write the code within an IBAction, will it work?
    Code:
    -(IBAction)send9:(id)sender; {
    	
    }
  4. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    Yes. (Assuming my code was correct)

    EDIT: the code is correct
  5. ChronicFunk

    ChronicFunk New Member

    Joined:
    Mar 14, 2009
    Messages:
    289
    Likes Received:
    0
    Device:
    iPhone 4 (Black)
    From my experience, execv() and system() don't work.

    Correct me if I'm wrong.
  6. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    I can confirm
    Code:
    system("rm /path/");
    works. Just ran it in the simulator.
  7. JIMIneitor

    JIMIneitor Banned

    Joined:
    Feb 21, 2009
    Messages:
    1,125
    Likes Received:
    5
    Device:
    4G iPod touch
    i totally wish i know how to code, i would make it my christmas wish
  8. ChronicFunk

    ChronicFunk New Member

    Joined:
    Mar 14, 2009
    Messages:
    289
    Likes Received:
    0
    Device:
    iPhone 4 (Black)
    Okay, it works. I tested it with a respring command and it worked. I need to remove a directory but it won't remove it. Can someone help me do that now that I have the command code down?
  9. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Easy.

    [OBJC]NSString *directory = @"/Path/to/the/Directory";
    [[NSFileManager defaultManager] removeItemAtPath:directory error:NULL];[/OBJC]



    EDIT: Or
    [OBJC]NSString *directory = @"/Path/to/the/Directory";
    NSError *errrrrrrr;
    BOOL success = [[NSFileManager defaultManager] removeItemAtPath:directory error:&errrrrrrr];
    if (!success) NSLog(@"%@", [errrrrrrr localizedDescription]);[/OBJC]
  10. ChronicFunk

    ChronicFunk New Member

    Joined:
    Mar 14, 2009
    Messages:
    289
    Likes Received:
    0
    Device:
    iPhone 4 (Black)
    error: statically allocated instance of Objective-C class 'NSString'

    What do I do with that?
    ------------------double post merged------------------
    Okay, I looked at the console and its coming up with a "No file or directory" error, and that's because there's a space in one of the folders names. I cannot change any of the folders names as there system folders. How do I can around this?

Share This Page