Mike's Question: I want to delete a directory that will have files in it...I don't know the name of the files.... there for wildcards might be needed....
I understand that "rmdir" will wipe out an empty directory....and "unlink" will wipe out files (only if I know the names of the files) What would be a nice command to remove a dirtory that had files in it? Even better.... what would be a nice command to delete all files in one directory... (leaving the directory intact) -------------------------------------------------------From Lamer: Simply Speaking, This would have been done better with these shell commands: # cd /directory # rm -rf * # cd ..; ------------------------------------------------------- >From Joost: #!/usr/bin/perl -w use File::Path; rmtree("some/dir", 0, 1); =pod man File::Path =cut -------------------------------------------------------From Craig: to remove a dirtory that had files in it: - rm -rf directory to delete all files in one directory (leaving the directory intact) - rm -rf directory/* to delete everything in a directory, including subdirectories - find . -type f | xargs rm -f to delete all files in a directory or its subdirectories, but keep the directory structure intact. Perl isn't required. -------------------------------------------------------From Bud: >Even better.... what would be a nice command to delete all filesin one directory... (leaving the directory intact) #! /usr/bin/perl -w $dir = "/path/to/dir"; opendir(DIR, $dir) or die "can't opendir $dir: $!"; while ( defined ($file = readdir DIR) ) { next if $file =~ /^\.\.?$/; # skip . and .. unlink $file; } Quick and dirty, but I think it will delete all files in one directory. Won't handle subdirs. Then you could probably just close(DIR); rmdir $dir; to get rid of the directory. ------------------------------------------------------- >From Larry Wall: "There's more than one way to do things" A fine example of life imitating art ;-) Scott Hamma __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/