How to remove a directory which has few files in it? I know about rmdir however it does not remove a dir which has files/dir in it!

Questions by Chintz   answers by Chintz

Showing Answers 1 - 54 of 54 Answers

amar reddy

  • Nov 27th, 2006
 

rm -r directoryname

  Was this answer useful?  Yes

Chintz

  • Nov 28th, 2006
 

I want to know about perl! How to remove a dir (which has multiple files in it) in perl?

  Was this answer useful?  Yes

I want to know the perl command and not unix! I know I can use this command through ``(backtick) however do we have a function in perl which removes the dir (which has files) ? rmdir removes only an empty dir!

  Was this answer useful?  Yes

Shreedhar Naik

  • Feb 7th, 2007
 

The PERL Command to remove a directory is: rmdir

  Was this answer useful?  Yes

madan kumar nath

  • Feb 14th, 2007
 

In Perl you can only remove emplty directories. To delete a non empty directory,you have to recurse into the directory, remove the files and then remove the files.

  Was this answer useful?  Yes

Vijay

  • Feb 16th, 2007
 

try system("rmdir /dir/filename");

  Was this answer useful?  Yes

Vijay

  • Feb 16th, 2007
 

Trysystem("rmdir /dir/dir1");

  Was this answer useful?  Yes

Jai Siddagangappa

  • Feb 16th, 2007
 

rmtree($dir) ;  

where, $dir = path where the directory to be removed, resides. for eg, to delete the Test dir in C:

$dir="C:Test"; 

  Was this answer useful?  Yes

Yograjkingaonkar

  • Mar 9th, 2007
 

rmdir definately doesnot work however you can use CPAN module File::Remove
Though it sounds like deleting file but it can be used also for deleting directories.
&File::Remove::remove (1, $feed_dir, $item_dir );

Removes files and directories. Directories are removed recursively like in rm -rf if the first argument is a reference to a scalar that evaluates to true. If the first arguemnt is a reference to a scalar then it is used as the value of the recursive flag. By default it's false so only pass 1 to it.

verman

  • Jul 4th, 2007
 

rm -fR <directory name>

this will forcefully delete the directory irespective of any files in it.

  Was this answer useful?  Yes

narendra meher

  • Aug 21st, 2007
 

We can use system command as

system("rm -rf dirname");

it will work

  Was this answer useful?  Yes

Prakash

  • Sep 22nd, 2007
 

User can use this

rm -rf <directoryName>


  Was this answer useful?  Yes

nitashaa

  • Jul 15th, 2008
 

1. system("rm -rf","directorypath");
2. A perl script can be created that'll make use of unlink , opendir,readdir,rmdir functions.
#!/usr/bin/perl
opendir(FD,"/home/tmp"); ---------> open tmp directory .Its just like open function
my @arr = readdir(FD); --------> read all the files in temp directory
closedir(FD);
print "list of files @arrn";
unlink(@arr); -------> remove all the files
rmdir("/home/tmp"); -------> remove tmp directory

Navrattan

  • Oct 8th, 2013
 

rmtree () is function which is used to remove a directory which has files in it

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions