Skip to content
Snippets Groups Projects
Commit 00133894 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Add FsUtils.CreateIncomingDirectories method

parent 4d623b5b
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using ATxCommon.Serializables;
using NLog;
namespace ATxCommon
......@@ -228,6 +229,42 @@ namespace ATxCommon
return retval;
}
/// <summary>
/// Helper to create directories for all users that have a dir in the local
/// user directory (C:\Users) AND in the DestinationDirectory.
/// </summary>
/// <param name="dest">The full path to the destination directory, as given in
/// <see cref="ServiceConfig.DestinationDirectory"/>.</param>
/// <param name="tmp">The (relative) path to the temporary transfer location, as given in
/// <see cref="ServiceConfig.TmpTransferDir"/>, commonly a single folder name.</param>
/// <param name="incoming">The full path to the incoming directory, as given in
/// <see cref="ServiceConfig.IncomingPath"/>.</param>
/// <returns>The DateTime.Now object upon success, exceptions propagated otherwise.</returns>
public static DateTime CreateIncomingDirectories(string dest, string tmp, string incoming) {
var localUserDirs = new DirectoryInfo(@"C:\Users")
.GetDirectories()
.Select(d => d.Name)
.ToArray();
var remoteUserDirs = new DirectoryInfo(dest)
.GetDirectories()
.Select(d => d.Name)
.ToArray();
foreach (var userDir in localUserDirs) {
// don't create an incoming directory for the same name as the
// temporary transfer location:
if (userDir == tmp)
continue;
// don't create a directory if it doesn't exist on the target:
if (!remoteUserDirs.Contains(userDir))
continue;
CreateNewDirectory(Path.Combine(incoming, userDir), false);
}
return DateTime.Now;
}
/// <summary>
/// Move all subdirectories of a given path into a destination directory. The destination
/// will be created if it doesn't exist yet. If a subdirectory of the same name already
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment