[LCP]recursive dir delete

Erik Mouw J.A.K.Mouw at its.tudelft.nl
Mon Feb 18 12:01:04 UTC 2002


On Fri, Feb 15, 2002 at 08:54:24AM -0000, mehul radheshyam choube wrote:
>   i am trying to write a c program which when given a directory path
>   will recursive delete the contents of the directory and then delete
>   the directory.

Nice as a programming excersise, but I think you just want "rm -rf".

>   which data structure should i use?(i think tree data structure).........

Because you have to follow the directory structure depth first, the
easiest way is to have a stack onto which you can push directories.

>   any ideas on data structures,some precautions,...

Be very careful not to follow symlinks: imagine a symlink to / when you
run the program as root... Also symlinks can create cycles in the
directory graph causing your program to loop forever (or until the
memory is exhausted).


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Faculty
of Information Technology and Systems, Delft University of Technology,
PO BOX 5031, 2600 GA Delft, The Netherlands  Phone: +31-15-2783635
Fax: +31-15-2781843  Email: J.A.K.Mouw at its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/



More information about the linuxCprogramming mailing list