private void CreateFolderIfNeeded(string folder) { IDirectoryInfo dir = _directoryInfoProvider.GetDirectoryInfo(folder); if (!dir.Exists) { dir.Create(); } }
private void ScanSubFoldersForOldFiles(string folderToScan, DateTime oldestEpisodeToKeep, List <IFileInfo> episodesToDelete, PodcastInfo podcastInfo) { IDirectoryInfo directoryInfo = _directoryInfoProvider.GetDirectoryInfo(folderToScan); IDirectoryInfo[] subFolders; try { subFolders = directoryInfo.GetDirectories("*.*"); } catch (DirectoryNotFoundException) { // if the folder is not there then there is nothing to do return; } foreach (IDirectoryInfo subFolder in subFolders) { ScanFolderForOldFiles(subFolder.FullName, oldestEpisodeToKeep, episodesToDelete, podcastInfo); } }
private void CreateFolderIfNeeded() { string folder = Path.GetDirectoryName(_syncItem.DestinationPath); IDirectoryInfo dir = _directoryInfoProvider.GetDirectoryInfo(folder); if (!dir.Exists) { dir.Create(); } if (_fileUtilities.FileExists(_syncItem.DestinationPath)) { _fileUtilities.FileDelete(_syncItem.DestinationPath); } }
/// <summary> /// remove a folder if there are no files in it, used by the synchroniser /// </summary> /// <param name="folder">folder to delete</param> /// <param name="whatIf">true to emit all the status updates but not actually perform the deletes, false to do the delete</param> public void RemoveFolderIfEmpty(string folder, bool whatIf) { IDirectoryInfo directoryInfo = _directoryInfoProvider.GetDirectoryInfo(folder); if (!directoryInfo.Exists) { return; } IDirectoryInfo[] subFolders; try { subFolders = directoryInfo.GetDirectories("*.*"); } catch (DirectoryNotFoundException) { // if the folder is not there then there is nothing to do return; } if (subFolders != null && subFolders.Length > 0) { // the folder is not empty - there are subfolders return; } IFileInfo[] files; try { files = directoryInfo.GetFiles("*.*"); } catch (DirectoryNotFoundException) { // if the folder is not there then there is nothing to do return; } if (files != null && files.Length > 0) { // the folder is not empty there are files return; } OnStatusUpdate(string.Format(CultureInfo.InvariantCulture, "Removing folder: {0}", directoryInfo.FullName)); if (!whatIf) { directoryInfo.Delete(); } }