|Hii all,
| i would like to know ,how do i delete all files in particular
|directoy .i don't know about name of files but i know from which
|directory i have to delete files.how should i do that??
The ri documentation for FileUtils.rm gives several examples, among which you
can find this:
FileUtils.rm Dir.glob('*.so')
This removes all files with extension .so from the current directory. To
remove *all* files from the current directory, you need to replace '*.so' with
'*' (which matches all file names):
require 'fileutils'
FileUtils.rm Dir.glob('*')
If you want to remove all files from another directory, you do:
require 'fileutils'
FileUtils.rm Dir.glob('/path/to/dir/*')
Note that this will give you errors in case the directory also contains
subdirectories. In this case, the correct approach depends on what you want to
obtain
* if you also want to remove the subdirectories, replace FileUtils.rm with
FileUtils.rm_r, which also remove directories
* if you don't want to touch subdirectories and their content, you can do
something like this:
Dir.glob('*').each do |f|
FileUtils.rm f unless File.directory? f
end
* if you want to delete the files in the subdirectories but keep the empty
subdirectories, you can do this:
require 'find'
Find.find('.') do |f|
next if File.directory? f
FileUtils.rm f
end
I hope this helps
Stefano