Exemplo n.º 1
0
 //删除文件或清空文件夹
 private static Boolean Delete(String filePath)
 {
     try
     {
         Boolean success = true;
         if (Directory.Exists(filePath))
         {
             DirectoryInfo dir = new DirectoryInfo(filePath);
             dir.Attributes = FileAttributes.Normal & FileAttributes.Directory; // 去掉文件夹只读属性
             foreach (FileInfo file in dir.GetFiles())                          // 删除所有文件
             {
                 File.SetAttributes(file.FullName, FileAttributes.Normal);      // 去掉文件只读属性
                 File.Delete(file.FullName);
             }
             foreach (DirectoryInfo subDir in dir.GetDirectories())                    // 删除所有子文件夹
             {
                 success = JskeyUpload.Delete(subDir.FullName) && success;;
             }
             Directory.Delete(filePath);                    //删除自己
         }
         else if (File.Exists(filePath))
         {
             File.SetAttributes(filePath, FileAttributes.Normal);                    // 去掉文件只读属性
             File.Delete(filePath);
         }
         return(success);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 2
0
        private static Timer GetTimer()        //临时目录初始化,在服务器启动时执行
        {
            if (JskeyUpload.UPLOAD_CLEAR)
            {
                JskeyUpload.Delete(JskeyUpload.UPLOAD_SAVEPATH);                //删除整个目录
            }
            Timer timer = new Timer(Convert.ToDouble(JskeyUpload.UPLOAD_TIMEOUT));

            timer.Elapsed  += new System.Timers.ElapsedEventHandler(delegate(Object source, ElapsedEventArgs e) { new JskeyUpload().Run(); });
            timer.AutoReset = true;
            timer.Enabled   = true;
            return(timer);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 删除指定的临时子目录
 /// </summary>
 /// <param name="sessionKey">用户临时主目录</param>
 /// <param name="fileKey">用户临时子目录</param>
 /// <returns>Boolean</returns>
 public static Boolean DelFile(long sessionKey, long fileKey)
 {
     try
     {
         if (sessionKey <= 0 || fileKey <= 0)
         {
             return(false);
         }
         JskeyUpload.Delete(JskeyUpload.UPLOAD_SAVEPATH + sessionKey + "/" + fileKey);                //删除整个目录
         return(true);
     }
     catch
     {
     }
     return(false);
 }
Exemplo n.º 4
0
 //删除整个临时上传目录
 private static Boolean DelSessionKey(long sessionKey)
 {
     try
     {
         if (sessionKey <= 0)
         {
             return(false);
         }
         JskeyUpload.Delete(JskeyUpload.UPLOAD_SAVEPATH + sessionKey + "/");
         JskeyUpload.RemoveSessionKey(sessionKey);                //移除标识
         return(true);
     }
     catch
     {
         JskeyUpload.RemoveSessionKey(sessionKey);                //移除标识
     }
     return(false);
 }