• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to remove a file from a directory?

 
Tong Chen
Ranch Hand
Posts: 1011
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am creating a script to delete some files from a given directory. Can anyone please tell me how to do that? Do you guys hava some snippets?
Thanks in advance,
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may use Apache ORO to build a list of files matching a Glob pattern (using ? and * in the filename).
1. Build a File object with the path to the directory where you want to delete files.
2. Create a org.apache.oro.io.GlobFilenameFilter that uses your matching pattern (e.g *.tmp).
3. Pass the globFilenameFilter object to the listFiles(FileFilter filter) method of your file object to list the files.
4. For each File object in the return array, call the delete() method to delete the file.
Good luck
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!