Find the answer to your Linux question:
Results 1 to 6 of 6
Can somebody tell me please how can I delete a directory along with all its sub directories and files in C?...
  1. #1
    Just Joined!
    Join Date
    Mar 2007
    Posts
    6

    How can a delete a whole directory?

    Can somebody tell me please how can I delete a directory along with all its sub directories and files in C?

  2. #2
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Hi anayd,

    Welcome to the LinuxForums.

    Code:
    rm -r <folder_name>
    check manual of 'rm' command.
    Code:
    man rm
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  3. #3
    Just Joined!
    Join Date
    Mar 2007
    Posts
    6
    Thank you devils_casper but I need to use that command in a C program.
    I have the name of the directory in a var name and I tried to use
    system("rm -r name"); but it doesn't work.

  4. #4
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    system function doesn't parse variables. concatenate 'rm -r' and directory name in a string xyz and pass it to system().
    system(xyz);
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  5. #5
    Banned jan1024188's Avatar
    Join Date
    Jul 2006
    Location
    EU, SLOVENIA
    Posts
    1,549
    sometimes may happen, that you will have to delete directory with force. In this case put rm -rf in your variable...

    BTW: Casper, I like your avatar.

  6. #6
    Just Joined!
    Join Date
    Mar 2007
    Posts
    6

    Thanks

    Thanks a lot devils_casper and jan1024188 ! It was very helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...