How can I tell if a file is locked?
Im using FTP to move log files.. but Im not sure how to tell if the server is still writing to the file.... Is there some way to determine if a file is locked (i.e. being written to... or held open by a process that may intend to write to it in the future)
Just for reference here is what Im doing now:
string BlankIfNotLockedOtherwiseFileIsLocked = ""
try {
ftp.Rename(currentFile.Name,currentFile.Name);
}catch(Exception err){
// If there is a file lock error the ReplyText will be:
// ReplyText: @[filename]: The process cannot access the file because it is being used by another process.
// The ReplyCode will be: 550
BlankIfNotLockedOtherwiseFileIsLocked = err.ToString();
}
if (BlankIfNotLockedOtherwiseFileIsLocked = ""){
// import the file
}else{
// leave it alone, its locked
}
This really seems like a bad way to do things... its a hack.. What I really want to do is just read some "isLocked" property.. or parse that out of some file information somewhere....