I have a routine that deletes files after they are zipped up. When I delete these though I am getting messages like the one below periodically. Here are my two delete methods. Does anyone know how I can force this?
The process cannot access the file "00000001.pdf" because it is being used
by another process.
private void PurgeDirectory(string DirectoryPath, bool recursive)
{
if (dsdo.ReturnCode == 0)
{
CallGarbageCollection();
PurgeFiles(DirectoryPath);
try
{
if
(utils.DoesDirectoryExist(DirectoryPath))
{
try
{
Directory.Delete(DirectoryPath, recursive);
if((utils.DoesDirectoryExist(DirectoryPath))&&(this.CountPurgeDirectories <=
30))
{
CountPurgeDirectories++;
Thread.Sleep(dsdo.Sleep);
PurgeDirectory(DirectoryPath);
}
}
catch
(DirectoryNotFoundException dnfe)
{
WriteLog("-
PurgeDirectory(string, bool) DirectoryNotFound " + dnfe.Message);
}
catch (Exception ex)
{
if((utils.DoesDirectoryExist(DirectoryPath))&&(this.CountPurgeDirectories <=
30))
{
CountPurgeDirectories++;
Thread.Sleep(dsdo.Sleep);
PurgeDirectory(DirectoryPath);
}
else
{
WriteLog("-
PurgeDirectory(string, bool) " + ex.Message);
dsdo.ReturnCode = 1;
}
}
}
}
catch (DirectoryNotFoundException dnfe2) {}
}
}
private void PurgeFiles(string DirectoryPath) {
FileInfo[] fis = null;
if (dsdo.ReturnCode == 0) {
CallGarbageCollection();
try {
if
(utils.DoesDirectoryExist(DirectoryPath)) {
try {
fis = new
DirectoryInfo(DirectoryPath).GetFiles(dsdo.FileFilter);
foreach (FileInfo f
in fis){
if(utils.DoesFileExist(f)){
try
{
f.Delete();
}
catch(Exception ex)
{
fis = new DirectoryInfo(DirectoryPath).GetFiles(dsdo.FileFilter);
if((fis.Length > 0)&&(CountPurgeFiles <=30))
{
CountPurgeFiles++;
Thread.Sleep(dsdo.Sleep);
PurgeFiles(DirectoryPath);
}
else{
WriteLog("- PurgeFiles(string) " + ex.Message);
}
}
}
}
fis = new
DirectoryInfo(DirectoryPath).GetFiles(dsdo.FileFilter);
if((fis.Length >
0)&&(CountPurgeFiles <=30)) {
CountPurgeFiles++;
Thread.Sleep(dsdo.Sleep);
PurgeFiles(DirectoryPath);
}
}
catch (FileNotFoundException
fnfe) {
fis = new
DirectoryInfo(DirectoryPath).GetFiles(dsdo.FileFilter);
if((fis.Length >
0)&&(CountPurgeFiles <=30))
{
CountPurgeFiles++;
Thread.Sleep(dsdo.Sleep);
PurgeFiles(DirectoryPath);
}
else
{
WriteLog("-
PurgeFiles(string) FileNotFound " + fnfe.Message);
}
}
catch (Exception ex) {
fis = new
DirectoryInfo(DirectoryPath).GetFiles(dsdo.FileFilter);
if((fis.Length >
0)&&(CountPurgeFiles <=30))
{
CountPurgeFiles++;
Thread.Sleep(dsdo.Sleep);
PurgeFiles(DirectoryPath);
}
else
{
WriteLog("-
PurgeFiles(string) " + ex.Message);
}
}
}
}
catch (DirectoryNotFoundException dnfe) {
WriteLog("- PurgeFiles(string)
DirectoryNotFound " + dnfe.Message);
}
}
}
Travis D. Falls | Consultant RAFT.Net IT | 860.547.4070 |
[EMAIL PROTECTED]
*************************************************************************
PRIVILEGED AND CONFIDENTIAL: This communication, including attachments, is
for the exclusive use of addressee and may contain proprietary,
confidential and/or privileged information. If you are not the intended
recipient, any use, copying, disclosure, dissemination or distribution is
strictly prohibited. If you are not the intended recipient, please notify
the sender immediately by return e-mail, delete this communication and
destroy all copies.
*************************************************************************
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
