Here are the examples of the csharp api System.IO.DirectoryInfo.GetDirectories(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
63 Examples
19
Source : EditorProjectUtilities.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from abist-co-ltd
private static FileInfo GetPackageCachereplacedemblyDefinitionFile(
DirectoryInfo root,
string folderName,
string fileName)
{
DirectoryInfo[] folders = root.GetDirectories(folderName);
if (folders.Length == 0)
{
return null;
}
if (folders.Length > 1)
{
Debug.LogWarning($"Too many instances of the {folderName} pattern, using the first one found.");
}
folders = folders[0].GetDirectories("Runtime");
if (folders.Length == 0)
{
return null;
}
FileInfo[] files = folders[0].GetFiles(fileName);
if (files.Length == 0)
{
return null;
}
return files[0];
}
19
Source : Extensions.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
public static DirectoryInfo[] GetDirectories(this RetryPolicy retryPolicy, DirectoryInfo directory, string searchPattern)
{
return retryPolicy.ExecuteAction(() => directory.GetDirectories(searchPattern));
}
19
Source : ExternalAGXInitializer.cs
with Apache License 2.0
from Algoryx
with Apache License 2.0
from Algoryx
private bool InitializeCheckout( string agxDir )
{
const int AGX_DEPENDENCIES = 0;
const int AGXTERRAIN_DEPENDENCIES = 1;
const int INSTALLED = 2;
Instance.AGX_DIR = agxDir;
var cmakeCache = new FileInfo( AGX_DIR + Path.DirectorySeparatorChar + "CMakeCache.txt" );
var binData = new BinDirData[]
{
new BinDirData()
{
CMakeKey = "CACHE_DEPENDENCY_DATE:STRING="
},
new BinDirData()
{
CMakeKey = "TERRAIN_DEPENDENCY_DATE:STRING="
},
new BinDirData()
{
CMakeKey = "CMAKE_INSTALL_PREFIX:PATH="
}
};
using ( var stream = cmakeCache.OpenText() ) {
var line = string.Empty;
while ( !binData.All( data => data.HasValue ) &&
( line = stream.ReadLine()?.Trim() ) != null ) {
if ( line.StartsWith( "//" ) )
continue;
binData.Any( data => data.StoreValue( line ) );
}
}
if ( !binData.All( data => data.HasValue ) ) {
foreach ( var data in binData )
if ( !data.HasValue )
Debug.LogError( $"{"ERROR".Color( Color.red )}: {data.CMakeKey}null" );
return false;
}
var dependenciesDir = new DirectoryInfo( AGX_DIR +
Path.DirectorySeparatorChar +
"dependencies" );
if ( !dependenciesDir.Exists ) {
Debug.LogError( $"{"ERROR".Color( Color.red )}: Dependencies directory {dependenciesDir.FullName} - doesn't exist." );
return false;
}
binData[ AGX_DEPENDENCIES ].Directory = dependenciesDir.GetDirectories( $"agx_dependencies_{binData[ AGX_DEPENDENCIES ].Value}*" ).FirstOrDefault();
binData[ AGXTERRAIN_DEPENDENCIES ].Directory = dependenciesDir.GetDirectories( $"agxTerrain_dependencies_{binData[ AGXTERRAIN_DEPENDENCIES ].Value}*" ).FirstOrDefault();
// Handle both absolute and relative CMAKE_INSTALL_PREFIX
var installPath = binData[ INSTALLED ].Value;
if ( Path.IsPathRooted( installPath ) )
binData[ INSTALLED ].Directory = new DirectoryInfo( installPath );
else
binData[ INSTALLED ].Directory = new DirectoryInfo( AGX_DIR +
Path.DirectorySeparatorChar +
installPath );
if ( binData.Any( data => data.Directory == null || !data.Directory.Exists ) ) {
foreach ( var data in binData )
if ( data.Directory == null || !data.Directory.Exists )
Debug.LogError( $"{"ERROR".Color( Color.red )}: Unable to find directory for key {data.CMakeKey}." );
return false;
}
AGX_BIN_PATH = ( from data in binData
select $"{data.Directory.FullName}{Path.DirectorySeparatorChar}bin{Path.DirectorySeparatorChar}x64" ).ToArray();
AGX_PLUGIN_PATH = $"{AGX_BIN_PATH[ INSTALLED ]}{Path.DirectorySeparatorChar}plugins";
AGX_DATA_DIR = $"{binData[ INSTALLED ].Directory.FullName}{Path.DirectorySeparatorChar}data";
return true;
}
19
Source : Solution.cs
with GNU General Public License v3.0
from AndreiFedarets
with GNU General Public License v3.0
from AndreiFedarets
private void DeleteDirectory(DirectoryInfo parentDirectory, string name)
{
DirectoryInfo[] directories = parentDirectory.GetDirectories(name);
foreach (DirectoryInfo directory in directories)
{
try
{
directory.Delete(true);
}
catch (Exception)
{
}
}
}
19
Source : AyFuncSystem.cs
with MIT License
from ay2015
with MIT License
from ay2015
public virtual string[] GetDotNetVersions()
{
DirectoryInfo[] directories = new DirectoryInfo(Environment.SystemDirectory + @"\..\Microsoft.NET\Framework").GetDirectories("v?.?.*");
System.Collections.ArrayList list = new System.Collections.ArrayList();
foreach (DirectoryInfo info2 in directories)
{
list.Add(info2.Name.Substring(1));
}
return (list.ToArray(typeof(string)) as string[]);
}
19
Source : GetChildItemCommand.cs
with BSD 3-Clause "New" or "Revised" License
from bitsadmin
with BSD 3-Clause "New" or "Revised" License
from bitsadmin
public static CommandResult BrowseFilesystem(string path, bool recurse, int depth, bool includeHidden, string searchPattern)
{
CommandResult results = new CommandResult();
DirectoryInfo gciDir = new DirectoryInfo(path);
if (!gciDir.Exists)
throw new ItemNotFoundException(path);
// TODO: Follow symlinks. Skipping them for now
if ((gciDir.Attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint)
return results;
DirectoryInfo[] directories;
try
{
directories = gciDir.GetDirectories(recurse ? "*" : searchPattern);
}
catch (UnauthorizedAccessException)
{
Console.WriteLine("Unauthorized to access \"{0}\"", path);
return results;
}
FileInfo[] files = gciDir.GetFiles(searchPattern);
// Enumerate directories
foreach (DirectoryInfo dir in directories)
{
if (!includeHidden && ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
continue;
// Don't show directories if -Recurse and an -Include filter is set
if (recurse && !string.IsNullOrEmpty(searchPattern))
continue;
ResultRecord currentDir = new ResultRecord()
{
{ "Mode", GetModeFlags(dir) },
{ "LastWriteTime", dir.LastWriteTime.ToString() },
{ "Length", string.Empty },
{ "Name", dir.Name }
};
// If recursive, also the directory name is needed
if (recurse)
currentDir.Add("Directory", dir.FullName);
results.Add(currentDir);
}
// Enumerate files
foreach (FileInfo file in files)
{
if (!includeHidden && ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
continue;
ResultRecord currentFile = new ResultRecord()
{
{ "Mode", GetModeFlags(file) },
{ "LastWriteTime", file.LastWriteTime.ToString() },
{ "Length", file.Length.ToString() },
{ "Name", file.Name }
};
// If recursive, also the directory name is needed
if (recurse)
currentFile.Add("Directory", file.Directory.FullName);
results.Add(currentFile);
}
// After adding folders and files in current directory, go depth first
if (recurse && depth > 0)
{
foreach (DirectoryInfo subDir in directories)
{
// Skip hidden directories in case -Force parameter is not provided
if ((subDir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden && !includeHidden)
continue;
CommandResult currentDir = BrowseFilesystem(subDir.FullName, recurse, depth - 1, includeHidden, searchPattern);
results.AddRange(currentDir);
}
}
return results;
}
19
Source : PathExtensions.cs
with GNU General Public License v3.0
from bonarr
with GNU General Public License v3.0
from bonarr
private static string GetProperCapitalization(DirectoryInfo dirInfo)
{
var parentDirInfo = dirInfo.Parent;
if (parentDirInfo == null)
{
//Drive letter
return dirInfo.Name.ToUpper();
}
var folderName = dirInfo.Name;
if (dirInfo.Exists)
{
folderName = parentDirInfo.GetDirectories(dirInfo.Name)[0].Name;
}
return Path.Combine(GetProperCapitalization(parentDirInfo), folderName);
}
19
Source : UpdateServiceFixture.cs
with GNU General Public License v3.0
from bonarr
with GNU General Public License v3.0
from bonarr
[Test]
[IntegrationTest]
public void Should_download_and_extract_to_temp_folder()
{
UseRealHttp();
var updateSubFolder = new DirectoryInfo(Mocker.GetMock<IAppFolderInfo>().Object.GetUpdateSandboxFolder());
updateSubFolder.Exists.Should().BeFalse();
Mocker.SetConstant<IArchiveService>(Mocker.Resolve<ArchiveService>());
Subject.Execute(new ApplicationUpdateCommand());
updateSubFolder.Refresh();
updateSubFolder.Exists.Should().BeTrue();
updateSubFolder.GetDirectories("NzbDrone").Should().HaveCount(1);
updateSubFolder.GetDirectories().Should().HaveCount(1);
updateSubFolder.GetFiles().Should().NotBeEmpty();
}
19
Source : Unity3DRider.cs
with MIT License
from bonzaiferroni
with MIT License
from bonzaiferroni
private static string[] GetAllRiderPaths()
{
switch (SystemInfoRiderPlugin.operatingSystemFamily)
{
case OperatingSystemFamily.Windows:
string[] folders =
{
@"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\JetBrains", Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
@"Microsoft\Windows\Start Menu\Programs\JetBrains Toolbox")
};
var newPathLnks = folders.Select(b => new DirectoryInfo(b)).Where(a => a.Exists)
.SelectMany(c => c.GetFiles("*Rider*.lnk")).ToArray();
if (newPathLnks.Any())
{
var newPaths = newPathLnks
.Select(newPathLnk => new FileInfo(ShortcutResolver.Resolve(newPathLnk.FullName)))
.Where(fi => File.Exists(fi.FullName))
.ToArray()
.OrderByDescending(fi => FileVersionInfo.GetVersionInfo(fi.FullName).ProductVersion)
.Select(a => a.FullName).ToArray();
return newPaths;
}
break;
case OperatingSystemFamily.MacOSX:
// "/Applications/*Rider*.app"
//"~/Applications/JetBrains Toolbox/*Rider*.app"
string[] foldersMac =
{
"/Applications", Path.Combine(Environment.GetEnvironmentVariable("HOME"), "Applications/JetBrains Toolbox")
};
var newPathsMac = foldersMac.Select(b => new DirectoryInfo(b)).Where(a => a.Exists)
.SelectMany(c => c.GetDirectories("*Rider*.app"))
.Select(a => a.FullName).ToArray();
return newPathsMac;
}
return new string[0];
}
19
Source : Discovery.cs
with MIT License
from chstetco
with MIT License
from chstetco
private static RiderInfo[] CollectRiderInfosMac()
{
var installInfos = new List<RiderInfo>();
// "/Applications/*Rider*.app"
var folder = new DirectoryInfo("/Applications");
if (folder.Exists)
{
installInfos.AddRange(folder.GetDirectories("*Rider*.app")
.Select(a => new RiderInfo(a.FullName, false))
.ToList());
}
// /Users/user/Library/Application Support/JetBrains/Toolbox/apps/Rider/ch-1/181.3870.267/Rider EAP.app
var toolboxRiderRootPath = GetToolboxBaseDir();
var paths = CollectPathsFromToolbox(toolboxRiderRootPath, "", "Rider*.app", true)
.Select(a => new RiderInfo(a, true));
installInfos.AddRange(paths);
return installInfos.ToArray();
}
19
Source : Discovery.cs
with MIT License
from chstetco
with MIT License
from chstetco
private static string[] GetExecutablePaths(string dirName, string searchPattern, bool isMac, string buildDir)
{
var folder = new DirectoryInfo(Path.Combine(buildDir, dirName));
if (!folder.Exists)
return new string[0];
if (!isMac)
return new[] {Path.Combine(folder.FullName, searchPattern)}.Where(File.Exists).ToArray();
return folder.GetDirectories(searchPattern).Select(f => f.FullName)
.Where(Directory.Exists).ToArray();
}
19
Source : DocAppender.cs
with MIT License
from CloudNimble
with MIT License
from CloudNimble
private string FindXmlDocPath(replacedembly replacedembly)
{
string asmPath = Uri.UnescapeDataString((new UriBuilder(replacedembly.CodeBase).Path));
string xmlPath;
// find same place
xmlPath = Path.ChangeExtension(asmPath, ".xml");
if (File.Exists(xmlPath))
{
return xmlPath;
}
// find from Reference replacedemblies
// ex. C:\Program Files (x86)\Reference replacedemblies\Microsoft\Framework\.NETFramework\v4.5.1
var baseDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
@"Reference replacedemblies\Microsoft\Framework\.NETFramework");
var dirInfo = new DirectoryInfo(baseDir);
if (dirInfo.Exists)
{
// find v4.* etc. directory
var pattern = replacedembly.ImageRuntimeVersion.Substring(0, 2) + ".*";
var verDirs = dirInfo.GetDirectories(pattern)
.OrderByDescending(dir => dir.Name)
.ToArray();
// find xml in version directory
var xmlName = Path.GetFileNameWithoutExtension(asmPath) + ".xml";
foreach (var verDir in verDirs)
{
xmlPath = Path.Combine(verDir.FullName, xmlName);
if (File.Exists(xmlPath))
{
return xmlPath;
}
}
}
// nothing
return null;
}
19
Source : MNative.cs
with MIT License
from CmlLib
with MIT License
from CmlLib
public void CleanNatives()
{
try
{
DirectoryInfo di = new DirectoryInfo(Minecraft.Versions + LaunchOption.StartProfile.Id);
foreach (var item in di.GetDirectories("native*"))
{
DeleteDirectory(item.FullName);
}
}
catch { }
}
19
Source : System_IO_DirectoryInfo_Binding.cs
with MIT License
from CragonGame
with MIT License
from CragonGame
static StackObject* GetDirectories_9(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 2);
ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.String @searchPattern = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.IO.DirectoryInfo instance_of_this_method = (System.IO.DirectoryInfo)typeof(System.IO.DirectoryInfo).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
var result_of_this_method = instance_of_this_method.GetDirectories(@searchPattern);
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}
19
Source : MainHostTests.cs
with Apache License 2.0
from damianh
with Apache License 2.0
from damianh
public static IWebHostBuilder UseNCrunchContentRoot(this IWebHostBuilder hostBuilder, string projectName)
{
// Not happy this exists. NCrunch copies things to it's own workspace fold structure that does not
// resemble that of the project repository. An alternative is tell NCrunch to copy wwwroot files.
// However, that is not what is done typically by the build. Am looking for improvement / alternative on this...
var originalProjectPath = Environment.GetEnvironmentVariable("NCrunch.OriginalProjectPath");
if (!string.IsNullOrWhiteSpace(originalProjectPath))
{
var contentRootDirectory = Directory.GetParent(originalProjectPath).Parent?
.GetDirectories(projectName)
.SingleOrDefault();
if (contentRootDirectory != null)
{
hostBuilder.UseContentRoot(contentRootDirectory.FullName);
}
}
return hostBuilder;
}
19
Source : Discovery.cs
with MIT License
from divjackdiv
with MIT License
from divjackdiv
private static RiderInfo[] CollectRiderInfosMac()
{
// "/Applications/*Rider*.app"
var folder = new DirectoryInfo("/Applications");
if (!folder.Exists)
return new RiderInfo[0];
var results = folder.GetDirectories("*Rider*.app")
.Select(a => new RiderInfo(a.FullName, false))
.ToList();
// /Users/user/Library/Application Support/JetBrains/Toolbox/apps/Rider/ch-1/181.3870.267/Rider EAP.app
var home = Environment.GetEnvironmentVariable("HOME");
if (!string.IsNullOrEmpty(home))
{
var toolboxRiderRootPath = Path.Combine(home, @"Library/Application Support/JetBrains/Toolbox/apps/Rider");
var paths = CollectPathsFromToolbox(toolboxRiderRootPath, "", "Rider*.app", true)
.Select(a => new RiderInfo(a, true));
results.AddRange(paths);
}
return results.ToArray();
}
19
Source : EditorProjectUtilities.cs
with MIT License
from doughtmw
with MIT License
from doughtmw
private static FileInfo GetPackageCachereplacedemblyDefinitionFile(
DirectoryInfo root,
string folderName,
string fileName)
{
DirectoryInfo[] folders = root.GetDirectories(folderName);
if (folders.Length == 0)
{
return null;
}
if (folders.Length > 1)
{
Debug.LogWarning($"Too many instances of the {folderName} pattern, using the first one found.");
}
folders = folders[0].GetDirectories("Runtime");
if (folders.Length == 0)
{
return null;
}
FileInfo[] files = folders[0].GetFiles(fileName);
if (files.Length == 0)
{
return null;
}
return files[0];
}
19
Source : XmlDocMarkdownGenerator.cs
with MIT License
from ejball
with MIT License
from ejball
private static IEnumerable<string> FindNamesMatchingPattern(DirectoryInfo directoryInfo, string namePattern, string requiredSubstring)
{
var parts = namePattern.Split(new[] { '/' }, 2);
if (parts[0].Length == 0)
throw new InvalidOperationException("Invalid name pattern.");
if (parts.Length == 1)
{
foreach (var fileInfo in directoryInfo.GetFiles(parts[0]))
{
if (File.ReadAllText(fileInfo.FullName).Contains(requiredSubstring))
yield return fileInfo.Name;
}
}
else
{
foreach (var subdirectoryInfo in directoryInfo.GetDirectories(parts[0]))
{
foreach (var name in FindNamesMatchingPattern(subdirectoryInfo, parts[1], requiredSubstring))
yield return subdirectoryInfo.Name + '/' + name;
}
}
}
19
Source : OptionsProvider.cs
with MIT License
from EliteAPI
with MIT License
from EliteAPI
public Task<FileInfo> FindActiveBindingsFile(DirectoryInfo optionsDirectory)
{
var bindingsDirectories = optionsDirectory.GetDirectories("Bindings");
if (bindingsDirectories.Length == 0)
{
throw new BindingsDirectoryNotFoundException("The bindings directory could not be found");
}
var bindingsDirectory = bindingsDirectories.First();
var fileFilter = !string.IsNullOrWhiteSpace(_config.GetSection("EliteAPI")["Bindings"]) ? _config.GetSection("EliteAPI")["Bindings"] : _codeConfig.BindingsFile;
var file = bindingsDirectory
.GetFiles(fileFilter)
.OrderByDescending(x => x.LastWriteTime)
.FirstOrDefault();
if (file == null)
{
throw new BindingsNotFoundException("Could not find a bindings file");
}
return Task.FromResult(file);
}
19
Source : TestProjectDuplicator.cs
with GNU General Public License v3.0
from Faultify
with GNU General Public License v3.0
from Faultify
public List<TestProjectDuplication> MakeInitialCopies(IProjectInfo testProject, int count)
{
var dirInfo = new DirectoryInfo(_testDirectory);
// Remove useless folders.
foreach (var directory in dirInfo.GetDirectories("*"))
{
var match = Regex.Match(directory.Name,
"(^cs$|^pl$|^rt$|^de$|^en$|^es$|^fr$|^it$|^ja$|^ko$|^ru$|^zh-Hans$|^zh-Hant$|^test-duplication-\\d$)");
if (match.Captures.Count != 0) Directory.Delete(directory.FullName, true);
}
var testProjectDuplications = new List<TestProjectDuplication>();
// Start the initial copy
var allFiles = Directory.GetFiles(_testDirectory, "*.*", SearchOption.AllDirectories).ToList();
var newDirInfo = Directory.CreateDirectory(Path.Combine(_testDirectory, "test-duplication-0"));
foreach (var file in allFiles)
try
{
var mFile = new FileInfo(file);
if (mFile.Directory.FullName == newDirInfo.Parent.FullName)
{
var newPath = Path.Combine(newDirInfo.FullName, mFile.Name);
mFile.MoveTo(newPath);
}
else
{
var path = mFile.FullName.Replace(newDirInfo.Parent.FullName, "");
var newPath = new FileInfo(Path.Combine(newDirInfo.FullName, path.Trim('\\')));
if (!Directory.Exists(newPath.DirectoryName)) Directory.CreateDirectory(newPath.DirectoryName);
mFile.MoveTo(newPath.FullName, true);
}
}
catch (Exception e)
{
throw e;
}
var initialCopies = testProject.ProjectReferences
.Select(x => new FileDuplication(newDirInfo.FullName, Path.GetFileNameWithoutExtension(x) + ".dll"));
testProjectDuplications.Add(new TestProjectDuplication(
new FileDuplication(newDirInfo.FullName, Path.GetFileName(testProject.replacedemblyPath)),
initialCopies,
0
));
// Copy the initial copy N times.
Parallel.ForEach(Enumerable.Range(1, count), i =>
{
var duplicatedDirectoryPath = Path.Combine(_testDirectory, $"test-duplication-{i}");
CopyFilesRecursively(newDirInfo, Directory.CreateDirectory(duplicatedDirectoryPath));
var duplicatedreplacedeblies = testProject.ProjectReferences
.Select(x =>
new FileDuplication(duplicatedDirectoryPath, Path.GetFileNameWithoutExtension(x) + ".dll"));
testProjectDuplications.Add(
new TestProjectDuplication(
new FileDuplication(duplicatedDirectoryPath, Path.GetFileName(testProject.replacedemblyPath)),
duplicatedreplacedeblies,
i
)
);
});
return testProjectDuplications;
}
19
Source : EditorPath.cs
with MIT License
from GameBuildingBlocks
with MIT License
from GameBuildingBlocks
public static void ScanDirectoryFile(string root, bool deep, List<string> list)
{
if (string.IsNullOrEmpty(root) || !Directory.Exists(root))
{
Debug.LogWarning("scan directory file failed! " + root);
return;
}
DirectoryInfo dirInfo = new DirectoryInfo(root);
FileInfo[] files = dirInfo.GetFiles("*.*");
for (int i = 0; i < files.Length; ++i)
{
list.Add(files[i].FullName);
}
if (deep)
{
DirectoryInfo[] dirs = dirInfo.GetDirectories("*.*");
for (int i = 0; i < dirs.Length; ++i)
{
ScanDirectoryFile(dirs[i].FullName, deep, list);
}
}
}
19
Source : SaveLoadScript.cs
with Apache License 2.0
from googlevr
with Apache License 2.0
from googlevr
public static IEnumerable<DiskSceneFileInfo> IterScenes(DirectoryInfo di) {
foreach (var sub in di.GetFiles("*"+TILT_SUFFIX)) {
yield return new DiskSceneFileInfo(sub.FullName);
}
foreach (var sub in di.GetDirectories("*"+TILT_SUFFIX)) {
yield return new DiskSceneFileInfo(sub.FullName);
}
}
19
Source : DirectoryInfo.cs
with MIT License
from GrapeCity
with MIT License
from GrapeCity
public DirectoryInfo [] GetDirectories () {
return GetDirectories ("*");
}
19
Source : BrowserFetcher.cs
with MIT License
from hardkoded
with MIT License
from hardkoded
private Task InstallDMGAsync(string dmgPath, string folderPath)
{
try
{
var destinationDirectoryInfo = new DirectoryInfo(folderPath);
if (!destinationDirectoryInfo.Exists)
{
destinationDirectoryInfo.Create();
}
var mountAndCopyTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
using var process = new Process
{
EnableRaisingEvents = true
};
process.StartInfo.FileName = "hdiutil";
process.StartInfo.Arguments = $"attach -nobrowse -noautoopen \"{dmgPath}\"";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.OutputDataReceived += (sender, e) =>
{
if (e.Data == null || mountAndCopyTcs.Task.IsCompleted)
{
return;
}
var volumes = new Regex("\\/Volumes\\/(.*)").Match(e.Data);
if (!volumes.Success)
{
return;
}
var mountPath = volumes.Captures[0];
var appFile = new DirectoryInfo(mountPath.Value).GetDirectories("*.app").FirstOrDefault();
if (appFile == null)
{
mountAndCopyTcs.TrySetException(new PuppeteerException($"Cannot find app in {mountPath.Value}"));
return;
}
using var process = new Process();
process.StartInfo.FileName = "cp";
process.StartInfo.Arguments = $"-R \"{appFile.FullName}\" \"{folderPath}\"";
process.Start();
process.WaitForExit();
mountAndCopyTcs.TrySetResult(true);
};
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
return mountAndCopyTcs.Task.WithTimeout(Puppeteer.DefaultTimeout);
}
finally
{
UnmountDmg(dmgPath);
}
}
19
Source : FilesystemSnapshotStore.cs
with Apache License 2.0
from Horusiath
with Apache License 2.0
from Horusiath
public async Task Save(Snapshot snapshot)
{
var seqNrString = $"{snapshot.SequenceNr:D19}";
var emitterDirectory = Uri.EscapeDataString(snapshot.EmitterId);
var subdirs = rootDirectory.GetDirectories(emitterDirectory);
var dir = subdirs.Length == 0 ? rootDirectory.CreateSubdirectory(emitterDirectory) : subdirs[0];
var tmpSnapshotFile = new FileInfo(Path.Combine(dir.FullName, $"tmp-{seqNrString}"));
if (!tmpSnapshotFile.Exists)
tmpSnapshotFile.Create();
using (var stream = tmpSnapshotFile.OpenWrite())
{
await Serialize(snapshot, stream);
}
tmpSnapshotFile.MoveTo(Path.Combine(dir.FullName, seqNrString));
// do not keep more than the configured maximum number of snapshot files
var files = dir.GetFiles();
if (files.Length > settings.SnapshotsPerEmitterMax)
{
for (int i = 0; i < files.Length - settings.SnapshotsPerEmitterMax; i++)
{
files[0].Delete();
}
}
}
19
Source : FilesystemSnapshotStore.cs
with Apache License 2.0
from Horusiath
with Apache License 2.0
from Horusiath
public async Task<Snapshot> Load(string emitterId)
{
var emitterDirectory = Uri.EscapeDataString(emitterId);
var subdirs = rootDirectory.GetDirectories(emitterDirectory);
if (subdirs.Length == 0)
return null;
else
{
var dir = subdirs[0];
var files = dir.GetFiles();
for (int i = files.Length - 1; i >= 0; i++)
{
var file = files[i];
if (!file.Name.StartsWith("tmp"))
{
try
{
using (var stream = file.OpenRead())
{
return await Deserialize(stream);
}
}
catch (Exception e)
{
logger.Warning("Failed to load snapshot from file", file.FullName);
}
}
}
}
return null;
}
19
Source : XDirectory.cs
with MIT License
from iccb1013
with MIT License
from iccb1013
private void DoWork(object StateInfo)
{
_CopierStatus = XDirectoryStatus.Started;
int iterator = 0;
List<DirectoryInfo> FolderSourceList = new List<DirectoryInfo>();
List<FileInfo> FileSourceList = new List<FileInfo>();
DirectoryInfo FolderPath;
FileInfo FilePath;
try
{
// Part 1: Indexing
///////////////////////////////////////////////////////
_CopierStatus = XDirectoryStatus.Indexing;
FolderSourceList.Add(_Source);
while (iterator < FolderSourceList.Count)
{
if (_CancelCopy) return;
foreach (DirectoryInfo di in FolderSourceList[iterator].GetDirectories(_FolderFilter))
{
if (_CancelCopy) return;
FolderSourceList.Add(di);
OnItemIndexed(new ItemIndexedEventArgs(
di.FullName,
0,
FolderSourceList.Count,
true));
}
foreach (string FileFilter in _FileFilters)
{
foreach (FileInfo fi in FolderSourceList[iterator].GetFiles(FileFilter))
{
if (_CancelCopy) return;
FileSourceList.Add(fi);
OnItemIndexed(new ItemIndexedEventArgs(
fi.FullName,
fi.Length,
FileSourceList.Count,
false));
}
}
iterator++;
}
OnIndexComplete(new IndexCompleteEventArgs(
FolderSourceList.Count,
FileSourceList.Count));
// Part 2: Destination Folder Creation
///////////////////////////////////////////////////////
_CopierStatus = XDirectoryStatus.CopyingFolders;
for (iterator = 0; iterator < FolderSourceList.Count; iterator++)
{
if (_CancelCopy) return;
if (FolderSourceList[iterator].Exists)
{
FolderPath = new DirectoryInfo(
_Destination.FullName +
Path.DirectorySeparatorChar +
FolderSourceList[iterator].FullName.Remove(0, _Source.FullName.Length));
try
{
if (!FolderPath.Exists) FolderPath.Create(); // Prevent IOException
OnItemCopied(new ItemCopiedEventArgs(
FolderSourceList[iterator].FullName,
FolderPath.FullName,
0,
iterator,
FolderSourceList.Count,
true));
}
catch (Exception iError)
{
OnCopyError(new CopyErrorEventArgs(
FolderSourceList[iterator].FullName,
FolderPath.FullName,
iError));
}
}
}
// Part 3: Source to Destination File Copy
///////////////////////////////////////////////////////
_CopierStatus = XDirectoryStatus.CopyingFiles;
for (iterator = 0; iterator < FileSourceList.Count; iterator++)
{
if (_CancelCopy) return;
if (FileSourceList[iterator].Exists)
{
FilePath = new FileInfo(
_Destination.FullName +
Path.DirectorySeparatorChar +
FileSourceList[iterator].FullName.Remove(0, _Source.FullName.Length + 1));
try
{
if (_Overwrite)
FileSourceList[iterator].CopyTo(FilePath.FullName, true);
else
{
if (!FilePath.Exists)
FileSourceList[iterator].CopyTo(FilePath.FullName, true);
}
OnItemCopied(new ItemCopiedEventArgs(
FileSourceList[iterator].FullName,
FilePath.FullName,
FileSourceList[iterator].Length,
iterator,
FileSourceList.Count,
false));
}
catch (Exception iError)
{
OnCopyError(new CopyErrorEventArgs(
FileSourceList[iterator].FullName,
FilePath.FullName,
iError));
}
}
}
}
catch
{ throw; }
finally
{
_CopierStatus = XDirectoryStatus.Stopped;
OnCopyComplete(new CopyCompleteEventArgs(_CancelCopy));
}
}
19
Source : FileTools.cs
with MIT License
from jeffcampbellmakesgames
with MIT License
from jeffcampbellmakesgames
private static void RecursivelyDeleteDirectoryContents(DirectoryInfo directoryInfo)
{
var subDirectoryInfo = directoryInfo.GetDirectories("*");
foreach (var sdi in subDirectoryInfo)
if ((sdi.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
sdi.Delete(true);
var fileInfo = directoryInfo.GetFiles("*");
foreach (var fi in fileInfo) fi.Delete();
}
19
Source : XNA_TerrariaLocator.cs
with GNU General Public License v3.0
from Jupisoft111
with GNU General Public License v3.0
from Jupisoft111
private static string GetProperDirectoryCapitalization(DirectoryInfo dirInfo)
{
DirectoryInfo parentDirInfo = dirInfo.Parent;
if (null == parentDirInfo)
return dirInfo.Name;
return Path.Combine(GetProperDirectoryCapitalization(parentDirInfo),
parentDirInfo.GetDirectories(dirInfo.Name)[0].Name);
}
19
Source : Util.cs
with MIT License
from kaby76
with MIT License
from kaby76
public static string GetProperDirectoryCapitalization(DirectoryInfo dirInfo)
{
DirectoryInfo parentDirInfo = dirInfo.Parent;
if (null == parentDirInfo)
{
return dirInfo.Name.ToUpper();
}
return Path.Combine(GetProperDirectoryCapitalization(parentDirInfo),
parentDirInfo.GetDirectories(dirInfo.Name)[0].Name);
}
19
Source : xDirectory.cs
with BSD 3-Clause "New" or "Revised" License
from Krypton-Suite
with BSD 3-Clause "New" or "Revised" License
from Krypton-Suite
private void DoWork(object StateInfo)
{
_copierStatus = xDirectoryStatus.STARTED;
int iterator = 0;
List<DirectoryInfo> FolderSourceList = new List<DirectoryInfo>();
List<FileInfo> FileSourceList = new List<FileInfo>();
DirectoryInfo FolderPath;
FileInfo FilePath;
try
{
// Part 1: Indexing
///////////////////////////////////////////////////////
_copierStatus = xDirectoryStatus.INDEXING;
FolderSourceList.Add(_source);
while (iterator < FolderSourceList.Count)
{
if (_cancelCopy) return;
foreach (DirectoryInfo di in FolderSourceList[iterator].GetDirectories(_folderFilter))
{
if (_cancelCopy) return;
FolderSourceList.Add(di);
OnItemIndexed(new ItemIndexedEventArgs(
di.FullName,
0,
FolderSourceList.Count,
true));
}
foreach (string FileFilter in _fileFilters)
{
foreach (FileInfo fi in FolderSourceList[iterator].GetFiles(FileFilter))
{
if (_cancelCopy) return;
FileSourceList.Add(fi);
OnItemIndexed(new ItemIndexedEventArgs(
fi.FullName,
fi.Length,
FileSourceList.Count,
false));
}
}
iterator++;
}
OnIndexComplete(new IndexCompleteEventArgs(
FolderSourceList.Count,
FileSourceList.Count));
// Part 2: Destination Folder Creation
///////////////////////////////////////////////////////
_copierStatus = xDirectoryStatus.COPYINGDIRECTORIES;
for (iterator = 0; iterator < FolderSourceList.Count; iterator++)
{
if (_cancelCopy) return;
if (FolderSourceList[iterator].Exists)
{
FolderPath = new DirectoryInfo(
_destination.FullName +
Path.DirectorySeparatorChar +
FolderSourceList[iterator].FullName.Remove(0, _source.FullName.Length));
try
{
if (!FolderPath.Exists) FolderPath.Create(); // Prevent IOException
OnItemCopied(new ItemCopiedEventArgs(
FolderSourceList[iterator].FullName,
FolderPath.FullName,
0,
iterator,
FolderSourceList.Count,
true));
}
catch (Exception iError)
{
OnCopyError(new CopyErrorEventArgs(
FolderSourceList[iterator].FullName,
FolderPath.FullName,
iError));
}
}
}
// Part 3: Source to Destination File Copy
///////////////////////////////////////////////////////
_copierStatus = xDirectoryStatus.COPYINGFILES;
for (iterator = 0; iterator < FileSourceList.Count; iterator++)
{
if (_cancelCopy) return;
if (FileSourceList[iterator].Exists)
{
FilePath = new FileInfo(_destination.FullName + Path.DirectorySeparatorChar + FileSourceList[iterator].FullName.Remove(0, _source.FullName.Length + 1));
try
{
if (_overwrite)
FileSourceList[iterator].CopyTo(FilePath.FullName, true);
else
{
if (!FilePath.Exists)
FileSourceList[iterator].CopyTo(FilePath.FullName, true);
}
OnItemCopied(new ItemCopiedEventArgs(
FileSourceList[iterator].FullName,
FilePath.FullName,
FileSourceList[iterator].Length,
iterator,
FileSourceList.Count,
false));
}
catch (Exception iError)
{
OnCopyError(new CopyErrorEventArgs(
FileSourceList[iterator].FullName,
FilePath.FullName,
iError));
}
}
}
}
catch
{ throw; }
finally
{
_copierStatus = xDirectoryStatus.STOPPED;
OnCopyComplete(new CopyCompleteEventArgs(_cancelCopy));
}
}
19
Source : ImageRepository.cs
with GNU General Public License v3.0
from Legolash2o
with GNU General Public License v3.0
from Legolash2o
private void CreateFSIFolder(DirectoryInfo fsobject, IFsiDirectoryItem diritem)
{
if (fsobject == null || diritem == null || _cancel)
return;
DirectoryInfo pysicalFolder = null;
pysicalFolder = new DirectoryInfo(UniqueListFileSystemInfo.GetPhysicalPath(fsobject.FullName.TrimEnd('\\')));
IFsiDirectoryItem crtdiritem = null;
if (diritem.FullPath.Length == 0)
{
try
{
var newpath = string.Format("{0}\\{1}", diritem.FullPath, pysicalFolder.Name);
if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory)
diritem.AddDirectory(pysicalFolder.Name);
}
catch
{
}
crtdiritem = diritem[pysicalFolder.Name] as IFsiDirectoryItem;
}
else
crtdiritem = diritem;
var files = pysicalFolder.GetFiles("*"); //all files
foreach (var file in files)
{
if (_cancel)
return;
CreateFSIFile(file, crtdiritem);
}
DirectoryInfo[] folders = null;
folders = pysicalFolder.GetDirectories("*");
if (folders != null && folders.Length > 0)
{
foreach (var folder in folders)
{
if (_cancel)
return;
try
{
var newpath = string.Format("{0}\\{1}", crtdiritem.FullPath, folder.Name);
if (_sysImage.Exists(newpath) != FsiItemType.FsiItemDirectory)
crtdiritem.AddDirectory(folder.Name);
}
catch
{
Cancel = true;
throw;
}
var subdir = crtdiritem[folder.Name] as IFsiDirectoryItem;
CreateFSIFolder(folder, subdir);
}
}
}
19
Source : UpdateServiceFixture.cs
with GNU General Public License v3.0
from Lidarr
with GNU General Public License v3.0
from Lidarr
[Test]
[IntegrationTest]
public void Should_download_and_extract_to_temp_folder()
{
UseRealHttp();
var updateSubFolder = new DirectoryInfo(Mocker.GetMock<IAppFolderInfo>().Object.GetUpdateSandboxFolder());
updateSubFolder.Exists.Should().BeFalse();
Mocker.SetConstant<IArchiveService>(Mocker.Resolve<ArchiveService>());
Subject.Execute(new ApplicationUpdateCommand());
updateSubFolder.Refresh();
updateSubFolder.Exists.Should().BeTrue();
updateSubFolder.GetDirectories("Lidarr").Should().HaveCount(1);
updateSubFolder.GetDirectories().Should().HaveCount(1);
updateSubFolder.GetFiles().Should().NotBeEmpty();
}
19
Source : ListIterateDirectories.cs
with MIT License
from luisdeol
with MIT License
from luisdeol
public static void GetExample()
{
var myDirectory = @"../../FileToCompress";
var myDirectoryInfo = new DirectoryInfo(myDirectory);
Console.WriteLine($"Sub-directories for: {myDirectoryInfo.Name}:");
foreach (var subDirectoryInfo in myDirectoryInfo.GetDirectories())
{
Console.WriteLine($"- {subDirectoryInfo.FullName}");
}
var directoriesContainingMore = myDirectoryInfo.GetDirectories("*more*");
Console.WriteLine("Directories containing 'more' word:");
foreach (var subDirectoryInfo in directoriesContainingMore)
{
Console.WriteLine($"- {subDirectoryInfo.FullName}");
}
}
19
Source : NuGetPackageResolver.cs
with MIT License
from matkoch
with MIT License
from matkoch
[CanBeNull]
public static InstalledPackage GetGlobalInstalledPackage(
string packageId,
[CanBeNull] VersionRange versionRange,
[CanBeNull] string packagesConfigFile,
bool? includePrereleases = null)
{
packageId = packageId.ToLowerInvariant();
var packagesDirectory = GetPackagesDirectory(packagesConfigFile);
if (packagesDirectory == null)
return null;
var packagesDirectoryInfo = new DirectoryInfo(packagesDirectory);
var packages = packagesDirectoryInfo
.GetDirectories(packageId)
.SelectMany(x => x.GetDirectories())
.SelectMany(x => x.GetFiles($"{packageId}*.nupkg"))
.Concat(packagesDirectoryInfo
.GetDirectories($"{packageId}*")
.SelectMany(x => x.GetFiles($"{packageId}*.nupkg")))
.Select(x => x.FullName);
var candidatePackages = packages.Select(x => new InstalledPackage(x))
// packages can contain false positives due to present/missing version specification
.Where(x => x.Id.EqualsOrdinalIgnoreCase(packageId))
.Where(x => !x.Version.IsPrerelease || !includePrereleases.HasValue || includePrereleases.Value)
.OrderByDescending(x => x.Version)
.ToList();
return versionRange == null
? candidatePackages.FirstOrDefault()
: candidatePackages.SingleOrDefault(x => x.Version == versionRange.FindBestMatch(candidatePackages.Select(y => y.Version)));
}
19
Source : ModWorker.cs
with GNU General Public License v3.0
from MatuxGG
with GNU General Public License v3.0
from MatuxGG
public void installLocalZip(Mod m)
{
string fileName = Path.GetFileName(m.github);
string tempPath = this.modManager.tempPath;
this.modManager.utils.DirectoryDelete(tempPath);
Directory.CreateDirectory(tempPath);
string tempPathZip = tempPath + "\\ModZip";
Directory.CreateDirectory(tempPathZip);
ZipFile.ExtractToDirectory(m.github, tempPathZip);
string newPath = this.getBepInExInsideRec(tempPathZip);
if (newPath != null)
{
tempPathZip = newPath;
}
string dirPlugins = this.modManager.config.amongUsPath + "\\BepInEx\\plugins";
// Install dll
DirectoryInfo dirInfo = new DirectoryInfo(tempPathZip + "\\BepInEx\\plugins");
if (Directory.Exists(dirPlugins) == false)
{
Directory.CreateDirectory(dirPlugins);
}
List<string> plugins = new List<string>();
if (dirInfo.Exists)
{
FileInfo[] files = dirInfo.GetFiles("*");
foreach (FileInfo f in files)
{
string target = dirPlugins + "\\" + f.Name;
string newName = f.Name;
if (File.Exists(target))
{
newName = m.id + "-" + f.Name.Remove(f.Name.Length - 4);
target = dirPlugins + "\\" + newName;
}
this.modManager.utils.FileCopy(f.FullName, target);
plugins.Add(newName);
}
DirectoryInfo[] dirs = dirInfo.GetDirectories("*");
foreach (DirectoryInfo d in dirs)
{
string target = dirPlugins + "\\" + d.Name;
string newName = d.Name;
if (Directory.Exists(target))
{
newName = m.id + "-" + d.Name.Remove(d.Name.Length);
target = dirPlugins + "\\" + newName;
}
this.modManager.utils.DirectoryCopy(d.FullName, target, true);
plugins.Add(newName);
}
}
string dirreplacedets = this.modManager.config.amongUsPath + "\\replacedets";
if (Directory.Exists(dirreplacedets) == false)
{
Directory.CreateDirectory(dirreplacedets);
}
DirectoryInfo dirInfo2 = new DirectoryInfo(tempPathZip + "\\replacedets");
if (dirInfo2.Exists)
{
FileInfo[] files = dirInfo2.GetFiles();
foreach (FileInfo f in files)
{
this.modManager.utils.FileCopy(f.FullName, dirreplacedets + "\\" + f.Name);
plugins.Add(f.FullName);
}
}
InstalledMod newMod = new InstalledMod(m.id, "1.0", m.gameVersion, plugins);
this.modManager.config.installedMods.Add(newMod);
this.modManager.config.update(this.modManager);
return;
}
19
Source : FileSystemShouldExtensions.cs
with MIT License
from microsoft
with MIT License
from microsoft
public DirectoryAdapter WithCaseMatchingName(string expectedName)
{
DirectoryInfo info = new DirectoryInfo(this.Path);
string parentPath = System.IO.Path.GetDirectoryName(this.Path);
DirectoryInfo parentInfo = new DirectoryInfo(parentPath);
expectedName.Equals(parentInfo.GetDirectories(info.Name)[0].Name, StringComparison.Ordinal)
.ShouldEqual(true, this.Path + " does not have the correct case");
return this;
}
19
Source : Paths.Shared.cs
with MIT License
from microsoft
with MIT License
from microsoft
public static string GetRoot(string startingDirectory, string rootName)
{
startingDirectory = startingDirectory.TrimEnd(Path.DirectorySeparatorChar);
DirectoryInfo dirInfo;
try
{
dirInfo = new DirectoryInfo(startingDirectory);
}
catch (Exception)
{
return null;
}
while (dirInfo != null)
{
if (dirInfo.Exists)
{
DirectoryInfo[] dotGVFSDirs = new DirectoryInfo[0];
try
{
dotGVFSDirs = dirInfo.GetDirectories(rootName);
}
catch (IOException)
{
}
if (dotGVFSDirs.Count() == 1)
{
return dirInfo.FullName;
}
}
dirInfo = dirInfo.Parent;
}
return null;
}
19
Source : Unity3DRider.cs
with MIT License
from miguel12345
with MIT License
from miguel12345
private static string GetDefaultApp()
{
var alreadySetPath = GetExternalScriptEditor();
if (!string.IsNullOrEmpty(alreadySetPath) && RiderPathExist(alreadySetPath))
return alreadySetPath;
switch (SystemInfoRiderPlugin.operatingSystemFamily)
{
case OperatingSystemFamily.Windows:
//"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\JetBrains\*Rider*.lnk"
//%appdata%\Microsoft\Windows\Start Menu\Programs\JetBrains Toolbox\*Rider*.lnk
string[] folders = {@"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\JetBrains", Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
@"Microsoft\Windows\Start Menu\Programs\JetBrains Toolbox")};
var newPathLnks = folders.Select(b=>new DirectoryInfo(b)).Where(a => a.Exists).SelectMany(c=>c.GetFiles("*Rider*.lnk"));
if (newPathLnks.Any())
{
var newPath = newPathLnks.Select(newPathLnk=> new FileInfo(ShortcutResolver.Resolve(newPathLnk.FullName))).OrderBy(a => FileVersionInfo.GetVersionInfo(a.FullName).ProductVersion).LastOrDefault();
if (!string.IsNullOrEmpty(newPath.FullName))
{
/*RiderPlugin.Log(LoggingLevel.Verbose, "Update {0} to {1} product version: {2}", alreadySetPath, newPath, FileVersionInfo.GetVersionInfo(newPath.FullName).ProductVersion);
SetExternalScriptEditor(newPath.FullName);*/
return newPath.FullName;
}
}
break;
case OperatingSystemFamily.MacOSX:
// "/Applications/*Rider*.app"
//"~/Applications/JetBrains Toolbox/*Rider*.app"
string[] foldersMac = {"/Applications",Path.Combine(Environment.GetEnvironmentVariable("HOME"), "Applications")};
var newPathMac = foldersMac.Select(b=>new DirectoryInfo(b)).Where(a => a.Exists)
.SelectMany(c=>c.GetDirectories("*Rider*.app")).OrderBy(a => FileVersionInfo.GetVersionInfo(a.FullName).ProductVersion).LastOrDefault();
if (newPathMac != null)
{
if (!string.IsNullOrEmpty(newPathMac.FullName))
{
/*Log(LoggingLevel.Verbose, "Update {0} to {1}", alreadySetPath, newPathMac);
SetExternalScriptEditor(newPathMac.FullName);*/
return newPathMac.FullName;
}
}
break;
}
var riderPath = GetExternalScriptEditor();
if (!RiderPathExist(riderPath))
{
Log(LoggingLevel.Warning, "Rider plugin for Unity is present, but Rider executable was not found. Please update 'External Script Editor'.");
return null;
}
return riderPath;
}
19
Source : UpdateXCodeProject.cs
with GNU General Public License v3.0
from mrojkov
with GNU General Public License v3.0
from mrojkov
static void CopyFiles(string source, string destination, string searchPattern)
{
var files = new DirectoryInfo(source).GetFiles(searchPattern);
foreach (var file in files) {
var destFile = Path.Combine(destination, file.Name);
Console.WriteLine("Writing " + destFile);
file.CopyTo(destFile, overwrite: true);
}
var dirs = new DirectoryInfo(source).GetDirectories(searchPattern);
foreach (var dir in dirs) {
var destDir = Path.Combine(destination, dir.Name);
Console.WriteLine("Writing " + destDir);
Directory.CreateDirectory(destDir);
CopyDirectoryRecursive(dir.FullName, destDir);
}
}
19
Source : NugetHelper.cs
with MIT License
from NetCoreStack
with MIT License
from NetCoreStack
private static replacedembly LoadCandidatereplacedembly(string packageId,
string extractFullPath,
List<string> candidateCompiledTarget)
{
if (candidateCompiledTarget != null && candidateCompiledTarget.Any())
{
var directoryInfo = new DirectoryInfo(extractFullPath);
foreach (var compiledTarget in candidateCompiledTarget)
{
var directories = directoryInfo.GetDirectories($"lib/{compiledTarget}");
if (directories.Any())
{
var libPath = directories.First();
var packageDll = libPath.GetFiles($"{packageId}.dll").FirstOrDefault();
if (packageDll != null)
{
return replacedemblyLoadContext.Default.LoadFromreplacedemblyPath(packageDll.FullName);
}
}
}
}
return null;
}
19
Source : NuGetPackageResolver.cs
with MIT License
from nuke-build
with MIT License
from nuke-build
[CanBeNull]
public static InstalledPackage GetGlobalInstalledPackage(
string packageId,
[CanBeNull] VersionRange versionRange,
[CanBeNull] string packagesConfigFile,
bool? includePrereleases = null)
{
packageId = packageId.ToLowerInvariant();
var packagesDirectory = GetPackagesDirectory(packagesConfigFile);
if (packagesDirectory == null)
return null;
var packagesDirectoryInfo = new DirectoryInfo(packagesDirectory);
var packages = packagesDirectoryInfo
.GetDirectories(packageId)
.SelectMany(x => x.GetDirectories())
.SelectMany(x => x.GetFiles($"{packageId}*.nupkg"))
.Concat(packagesDirectoryInfo
.GetDirectories($"{packageId}*")
.SelectMany(x => x.GetFiles($"{packageId}*.nupkg")))
.Where(x => x.Name.StartsWithOrdinalIgnoreCase(packageId))
.Select(x => x.FullName);
var candidatePackages = packages.Select(x => new InstalledPackage(x))
// packages can contain false positives due to present/missing version specification
.Where(x => x.Id.EqualsOrdinalIgnoreCase(packageId))
.Where(x => !x.Version.IsPrerelease || !includePrereleases.HasValue || includePrereleases.Value)
.OrderByDescending(x => x.Version)
.ToList();
return versionRange == null
? candidatePackages.FirstOrDefault()
: candidatePackages.SingleOrDefault(x => x.Version == versionRange.FindBestMatch(candidatePackages.Select(y => y.Version)));
}
19
Source : StringExtensions.cs
with GNU General Public License v3.0
from PlexRipper
with GNU General Public License v3.0
from PlexRipper
private static string GetProperCapitalization(DirectoryInfo dirInfo)
{
var parentDirInfo = dirInfo.Parent;
if (parentDirInfo == null)
{
// Drive letter
return dirInfo.Name.ToUpper();
}
var folderName = dirInfo.Name;
if (dirInfo.Exists)
{
folderName = parentDirInfo.GetDirectories(dirInfo.Name)[0].Name;
}
return Path.Combine(GetProperCapitalization(parentDirInfo), folderName);
}
19
Source : QueueForm.cs
with Apache License 2.0
from ProteoWizard
with Apache License 2.0
from ProteoWizard
private bool DetectLatestIDPicker()
{
var basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Bumbershoot");
if (Directory.Exists(basePath))
{
var DI = new DirectoryInfo(basePath);
var dirList = DI.GetDirectories("IDPicker*").OrderByDescending(x => x.Name).ToList();
if (!dirList.Any())
return false;
if (File.Exists(Path.Combine(dirList[0].FullName, "IDPicker.exe")))
{
Properties.Settings.Default.IDPickerLocation = Path.Combine(dirList[0].FullName, "IDPicker.exe");
Properties.Settings.Default.Save();
return true;
}
if (File.Exists(Path.Combine(dirList[0].FullName, "IdPickerGui.exe")))
{
Properties.Settings.Default.IDPickerLocation = Path.Combine(dirList[0].FullName, "IdPickerGui.exe");
Properties.Settings.Default.Save();
return true;
}
}
return false;
}
19
Source : UpdateServiceFixture.cs
with GNU General Public License v3.0
from Readarr
with GNU General Public License v3.0
from Readarr
[Test]
[IntegrationTest]
[Ignore("Until release published")]
public void Should_download_and_extract_to_temp_folder()
{
UseRealHttp();
var updateSubFolder = new DirectoryInfo(Mocker.GetMock<IAppFolderInfo>().Object.GetUpdateSandboxFolder());
updateSubFolder.Exists.Should().BeFalse();
Mocker.SetConstant<IArchiveService>(Mocker.Resolve<ArchiveService>());
Subject.Execute(new ApplicationUpdateCommand());
updateSubFolder.Refresh();
updateSubFolder.Exists.Should().BeTrue();
updateSubFolder.GetDirectories("Readarr").Should().HaveCount(1);
updateSubFolder.GetDirectories().Should().HaveCount(1);
updateSubFolder.GetFiles().Should().NotBeEmpty();
}
19
Source : DirectoryInfo.cs
with MIT License
from roozbehid
with MIT License
from roozbehid
public DirectoryInfo [] GetDirectories ()
{
return GetDirectories ("*");
}
19
Source : Build.cs
with MIT License
from Rufus31415
with MIT License
from Rufus31415
[MenuItem("SimpleWebXR/Build/Examples")]
public static void BuildAll()
{
ClearBuildFolder();
var sceneFolder = Path.Combine(Application.dataPath, "SimpleWebXR", "Scenes");
var scenes = Directory.GetFiles(sceneFolder, "*.unity");
foreach (var scene in scenes)
{
var projectName = Path.GetFileNameWithoutExtension(scene);
var locationPathName = Path.Combine(BuildPath, projectName);
if (!Directory.Exists(locationPathName)) Directory.CreateDirectory(locationPathName);
if (scene.Contains("Hololens2"))
{
var generationPath = Path.Combine(UWPTempPath, projectName);
BuildPlayerOptions opts = new BuildPlayerOptions
{
scenes = new string[] { scene },
targetGroup = BuildTargetGroup.WSA,
target = BuildTarget.WSAPlayer,
locationPathName = generationPath
};
BuildPipeline.BuildPlayer(opts);
var generationFolder = new DirectoryInfo(generationPath);
var slnPath = generationFolder.GetFiles("*.sln").FirstOrDefault()?.FullName;
if (slnPath == null) throw new Exception($"No sln file in folder {generationFolder.FullName}");
string pathToMSBuild;
string error;
using (var process = new Process())
{
if (0 != process.Run(@"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe", @"-latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe", Application.dataPath, out pathToMSBuild, out error))
{
throw new Exception($"Unable to locate MSBuild.exe : {error}");
}
}
if (string.IsNullOrEmpty(pathToMSBuild)) throw new Exception("Unable to access MSBuild individual component, please install it.");
string msBuildOutput;
using (var process = new Process())
{
if (0 != process.Run(pathToMSBuild, $"/t:Build /p:Configuration=Master /p:Platform=ARM /verbosity:m \"{slnPath}\"", Application.dataPath, out msBuildOutput, out error))
{
throw new Exception("MSBuild compilation failed", new Exception(msBuildOutput));
}
}
var appxFolder = generationFolder.GetDirectories()
.FirstOrDefault((x) => string.Equals(x.Name, "AppPackages", StringComparison.InvariantCultureIgnoreCase)) // dossier AppPackages
?.GetDirectories()?.FirstOrDefault() // dossier du nom du package
?.GetDirectories()?.FirstOrDefault(); // dossier du nom de la plateforme
if (appxFolder == null || !appxFolder.Exists) throw new Exception($"Output folders in AppPackages don't exist for project {generationFolder.FullName}");
var appxFile = appxFolder.GetFiles("*.appx")?.FirstOrDefault();
if (appxFile == null) appxFile = appxFolder.GetFiles("*.msix")?.FirstOrDefault();
var cerFile = appxFolder.GetFiles("*.cer")?.FirstOrDefault();
var dependencieFile = appxFolder.GetDirectories("Dependencies")?.FirstOrDefault()?.GetDirectories(EditorUserBuildSettings.wsaArchitecture)?.FirstOrDefault()?.GetFiles("*.appx")?.FirstOrDefault();
if (appxFile == null || cerFile == null || dependencieFile == null) throw new Exception($"Appx file not found for project {generationFolder.FullName}");
var targetFolder = new DirectoryInfo(Path.Combine(BuildPath, projectName));
if (targetFolder.Exists) targetFolder.Delete(true);
targetFolder.Create();
appxFile.CopyTo(Path.Combine(targetFolder.FullName, appxFile.Name));
cerFile.CopyTo(Path.Combine(targetFolder.FullName, cerFile.Name));
dependencieFile.CopyTo(Path.Combine(targetFolder.FullName, dependencieFile.Name));
}
else
{
BuildPlayerOptions opts = new BuildPlayerOptions
{
scenes = new string[] { scene },
targetGroup = BuildTargetGroup.WebGL,
target = BuildTarget.WebGL,
locationPathName = locationPathName
};
BuildPipeline.BuildPlayer(opts);
}
}
BuildUnityPackages();
}
19
Source : WorkingCopy.cs
with MIT License
from saintedlama
with MIT License
from saintedlama
public static WorkingCopy Discover(string workingDirectory)
{
var workingCopyCandidate = new DirectoryInfo(workingDirectory);
if (!workingCopyCandidate.Exists)
{
Exit($"Directory {workingDirectory} does not exist", 2);
}
do
{
var isWorkingCopy = workingCopyCandidate.GetDirectories(".git").Any();
if (isWorkingCopy)
{
return new WorkingCopy(workingCopyCandidate);
}
workingCopyCandidate = workingCopyCandidate.Parent;
}
while (workingCopyCandidate.Parent != null);
Exit($"Directory {workingDirectory} or any parent directory do not contain a git working copy", 3);
return null;
}
19
Source : MainWindow.xaml.cs
with GNU General Public License v3.0
from starflash-studios
with GNU General Public License v3.0
from starflash-studios
public static List<DirectoryInfo> GetLazerVersions() {
List<DirectoryInfo> AppVersions = LazerInstallationPath?.GetDirectories("app-*").ToList() ?? new List<DirectoryInfo>();
AppVersions.Reverse();
return AppVersions;
}
19
Source : NordVPN.cs
with GNU General Public License v3.0
from swagkarna
with GNU General Public License v3.0
from swagkarna
public static void Save(string sSavePath)
{
// "NordVPN" directory path
DirectoryInfo vpn = new DirectoryInfo(Path.Combine(Paths.lappdata, "NordVPN"));
// Stop if not exists
if (!vpn.Exists)
return;
try
{
Directory.CreateDirectory(sSavePath);
// Search user.config
foreach (DirectoryInfo d in vpn.GetDirectories("NordVpn.exe*"))
foreach (DirectoryInfo v in d.GetDirectories())
{
string userConfigPath = Path.Combine(v.FullName, "user.config");
if (File.Exists(userConfigPath))
{
// Create directory with VPN version to collect accounts
Directory.CreateDirectory(sSavePath + "\\" + v.Name);
var doc = new XmlDoreplacedent();
doc.Load(userConfigPath);
string encodedUsername = doc.SelectSingleNode("//setting[@name='Username']/value").InnerText;
string encodedPreplacedword = doc.SelectSingleNode("//setting[@name='Preplacedword']/value").InnerText;
if (encodedUsername != null && !string.IsNullOrEmpty(encodedUsername) &&
encodedPreplacedword != null && !string.IsNullOrEmpty(encodedPreplacedword))
{
string username = Decode(encodedUsername);
string preplacedword = Decode(encodedPreplacedword);
Counter.VPN++;
File.AppendAllText(sSavePath + "\\" + v.Name + "\\accounts.txt", $"Username: {username}\nPreplacedword: {preplacedword}\n\n");
}
}
}
}
catch { }
}
See More Examples