codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Why cannot delete file  wkw510 at 01:35 on Friday, December 05, 2003
 

Dear all,
My problem here is after I ran my code, I cant delete the origin file that I have ftp it. For example, I ftp C:\a\a.txt to /home/kwwong/upload/a.txt. After doing this, I need to delete C:\a\a.txt but I got this message "Cannot delete a.txt:It is being used by another person or program".
Anyone knows what wrong with my code here?
Any helps are appreciated. Thank you very much.

BufferedReader reader = null;
Ftp ftp = null;
String tmp = null;
InetAddress Inet = null;
try{
String lStrUploadFileLog = "C:/FTPLog/FTPLog_05122003.log";
String lStrUploadFilePath = "/home/kwwong/upload/";
String lStrFTP_USER = "kwwong";
String lStrFTP_PWD = "password";
String lStrFTP_IP = "192.168.1.100";
String lStrLogFileDate = "LOG_FILE_DATE";

reader = new BufferedReader(new FileReader(new File(lStrUploadFileLog)));
Inet = InetAddress.getByName(lStrFTP_IP);
tmp = reader.readLine();
ftp = new Ftp(Inet,lStrFTP_USER,lStrFTP_PWD);
ftp.setType(ftp.BINARY);

if(tmp != null){
System.out.println("lStrUploadFileLog = "+lStrUploadFileLog);
System.out.println("lStrUploadFilePath+lStrLogFileDate = "+(lStrUploadFilePath+lStrLogFileDate));
ftp.startPut(lStrUploadFileLog,lStrUploadFilePath+lStrLogFileDate);
System.out.println("tmp = "+tmp);
StringTokenizer strtmp = new StringTokenizer(tmp,",");
int size_strtmp = strtmp.countTokens();

while (size_strtmp>0){
String lStrUploadFile = strtmp.nextToken();
size_strtmp--;
StringTokenizer strlStrUploadFile = new StringTokenizer(lStrUploadFile,"\\");
int size_strlStrUploadFile = strlStrUploadFile.countTokens();
String substr = lStrUploadFile.substring(lStrUploadFile.lastIndexOf("\\")+1,lStrUploadFile.length());

ftp.startPut(lStrUploadFile,lStrUploadFilePath+substr);
ftp.waitUntilTransferComplete();

System.out.println("File(s) download completed!");
}
try {
File ff = new File(lStrUploadFileLog);
System.out.println(ff.getAbsolutePath());
boolean state = ff.delete();
System.out.println(state);
} catch ( SecurityException se ) {
System.out.println("Error SecurityException: "+se );
se.printStackTrace();
}
catch(Exception e){
System.out.println("Error Exception1: "+e );
e.printStackTrace();
}
}
System.out.println("Upload to server completed!!!");
}catch(Exception e){

System.out.println("Error Exception: "+e);
}
finally{
if(reader != null)
reader.close();
if(ftp != null)
ftp.close();
reader = null;
ftp = null;
tmp = null;
Inet = null;
}

  Re: Why cannot delete file  bz1976 at 21:23 on Wednesday, June 08, 2005
 

its simple. start up in safe mode and simply delete the file. if that doesnt't work try opening NOTEPAD and saving blank as same type of file you are trying to delete. hope this works for you.

  Re: Why cannot delete file  bz1976 at 21:23 on Wednesday, June 08, 2005
 

its simple. start up in safe mode and simply delete the file. if that doesnt't work try opening NOTEPAD and saving blank as same type of file you are trying to delete. hope this works for you.

  Re: Why cannot delete file  keeym at 08:52 on Wednesday, April 25, 2007
 

Me also having the same problem when i tried to delete those attached files via email by using C# code as follows:

sourceDir = @"C:\Inetpub\wwwroot\Report\Attachment\";
string[] fileEntries = Directory.GetFiles(sourceDir);

foreach (string fileName in fileEntries)
{

System.IO.File.Delete(fileName);
}

Appreciate if anyone can help.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: dynamic crystal report generation
•  Writing form data to output files
•  date of birth validation using java script-very urgent
•  c++ beginner need some help
•  Menu.Prototype.cssFile
•  Perl`s Greedy and Non-Greedy Quantifiers
•  Perl`s Regular Expression Engine
•  Perl`s Regular Expression Engine
•  mysql issue with delete


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007