/// <summary> /// Deletes multiple resized instances of an image file /// </summary> /// <param name="filePath">A sample of the filename to be deleted. Ex: my_image-w800.jpg</param> public void DeleteImageWithMultipleSizes(string filePath) { Filepath filepath = new Filepath(filePath); Filename filename = new Filename(filepath.Filename); Regex findWidthTag = new Regex("-w[0-9]+$"); filename.BaseName = findWidthTag.Replace(filename.BaseName, "-w*"); filepath.Filename = filename.FileName; DeleteFilesWithWildcard(filepath.FilePath); }
/// <summary> /// Deletes all files from the server matching a wildcard pattern /// </summary> /// <param name="filePath">The filepath of the files to be deleted including wildcards in the filename</param> public void DeleteFilesWithWildcard(string filePath) { Filepath filepath = new Filepath(filePath); // Can't delete files outside the scope of this FileSystemService if (!filepath.Path.Equals(BaseUrlPath)) { throw new DirectoryNotFoundException("Invalid directory"); } var files = Directory.GetFiles(BaseDiskPath, filepath.Filename); foreach (string file in files) { DeleteFile(file); } }