Results 1 to 2 of 2

Thread: RESOLVED delete a file older than thirty days I am getting a directory Invalid error

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    790

    Resolved RESOLVED delete a file older than thirty days I am getting a directory Invalid error

    I placed this code yesterday which focuses on deleting a file older the thirty days and this process checks after my streamwriter code the whole thing looks like this :

    Code:
     public LoggingAction( GlobalConfiguration globalConfig, PayFilePackageCol paymentfilePackCol)
    
            {
                GlobalConfig = globalConfig;
                PayFilePackCol = paymentfilePackCol;
                logfilePath1 = this.GlobalConfig.Payment_Log_File_Loc;
    
    
          
    
    
        
    
    
    
                String folder = Path.GetDirectoryName(logfilePath1);
                String fileName = Path.GetFileNameWithoutExtension(logfilePath1);
                String extension = Path.GetExtension(logfilePath1);
    
                String newName = folder + "\\" + fileName + "_" + ISO_Date() + extension;
    
             
    
                pSW = new StreamWriter(newName, true);
    
    
    
                string[] files = Directory.GetFiles(newName);
                foreach (string file in files)
                {
                    FileInfo fi = new FileInfo(file);
                    if (fi.LastAccessTime < DateTime.Now.AddDays(-30))
    
                        fi.Delete();
                } 
    
    
    
    
    
    
            }
    
    
            ~LoggingAction()
            {
    now the global config. Payment_Log_File_Loc is acutally C:\Temp on my local c drive so unless my permissions are set that I can't delete from there what else could be going on to fire off that exception ?
    Last edited by Christopher_Arm; Oct 7th, 2011 at 01:49 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width