//------------------------Delete the actual file-------------------------------------------- public string[] DeleteOne(int number) { string body = ""; string path = "/messages"; string theWay = (AppDomain.CurrentDomain.BaseDirectory + path); //get the the path of the program (there also lies the message folder) DirectoryInfo directory = new DirectoryInfo(theWay); FileInfo[] files = _fileHandler.GetFileInfo(theWay); //FileInfo[] files = directory.GetFiles("*.txt"); if (files.Length < number) { body = "File Number " + number.ToString() + " is not available"; string[] firstResponse = { "text/plain", "200 Request sucess", body }; return(firstResponse); } else { _fileHandler.Delete(files, number); //File.Delete(files[number - 1].ToString()); //file gets deleted body = "File Number " + number.ToString() + " is deleted"; string[] secondResponse = { "text/plain", "200 Request sucess", body }; return(secondResponse); } }
public async Task <Unit> Invoke(IUnitOfWork uow) { var dbContext = new DbContext(uow); var file = await dbContext.File.GetFileByID(_guid); if (file == null) { throw new NotFoundException(); } await _fileHandler.Delete(file.Directory, file.ID.ToString()); await dbContext.File.DeleteFile(_guid); return(Unit.Default); }
internal void ClearAll() { foreach (DirectoryInfo dir in baseDirectory.GetDirectories()) { foreach (FileInfo file in dir.GetFiles()) { Mutex mutex = new Mutex(false, file.FullName); mutex.WaitOne(); try { fileHandler.Delete(file.FullName); } finally { mutex.ReleaseMutex(); } } dir.Delete(true); } }