Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to delete multiple files from a directory Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delete multiple files from a directory 19-Sep-04
Category
Files Operation
Language
JBuilder All Versions
Views
373
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
Darley, F. Joe
Reference URL:
			1   
2   import java.awt.*;
3   import java.awt.event.*;
4   import javax.swing.*;
5   import java.io.*;
6   
7   void  DeleteFiles(String sExt, String sPath){
8       File fDirectory = new File(sPath); 
9       File[]  aFile= fDirectory.listFiles();//list all files in directory
10    
11      for( int i=0; i<aFile.length; i++){// loop through content of directory
12      if(aFile[i].isFile()){ //check if its a file
13       String sFile=  aFile[i].toString(); //gets a string
14       sFile= sFile.toLowerCase(); // set it to lowercase
15    if( sFile.endsWith(sExt) ==true){ //check if the file ends with extention
16         aFile[i].delete(); //deletes file
17       }
18      } 
19      }
20   }
21          
22  
23    void jButton2_actionPerformed(ActionEvent e) {
24      
25    //Call to delete files use lowercase for sending mask   
26      DeleteFiles(".txt","C:\\Test\\");
27  
28    }
29  


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC