quick fix of files path
This commit is contained in:
@@ -10,8 +10,8 @@ public static class Directory
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
// проверяет существование папки, в которой нужно создать dir
|
||||
if (dir.Contains('\\') && !Directory.Exists(dir.Remove(dir.LastIndexOf('\\'))))
|
||||
Create(dir.Remove(dir.LastIndexOf('\\')));
|
||||
if (dir.Contains(Path.Sep) && !Directory.Exists(dir.Remove(dir.LastIndexOf(Path.Sep))))
|
||||
Create(dir.Remove(dir.LastIndexOf(Path.Sep)));
|
||||
System.IO.Directory.CreateDirectory(dir);
|
||||
}
|
||||
}
|
||||
@@ -100,8 +100,8 @@ public static class Directory
|
||||
|
||||
public static void CreateSymlink(string sourceName, string symlinkName)
|
||||
{
|
||||
if (symlinkName.Contains("\\"))
|
||||
Directory.Create(symlinkName.Remove(symlinkName.LastIndexOf('\\')));
|
||||
if (symlinkName.Contains(Path.Sep))
|
||||
Directory.Create(symlinkName.Remove(symlinkName.LastIndexOf(Path.Sep)));
|
||||
if (!Symlink.CreateSymbolicLink(symlinkName, sourceName, Symlink.SymlinkTarget.Directory))
|
||||
throw new InvalidOperationException($"some error occured while creating symlink\nDirectory.CreateSymlink({symlinkName}, {sourceName})");
|
||||
}
|
||||
@@ -110,8 +110,8 @@ public static class Directory
|
||||
public static int SymCopy(string srcdir, string newdir)
|
||||
{
|
||||
List<string> files = Directory.GetAllFiles(srcdir);
|
||||
if (!srcdir.EndsWith('\\')) srcdir += '\\';
|
||||
if (!newdir.EndsWith('\\')) newdir += '\\';
|
||||
if (!srcdir.EndsWith(Path.Sep)) srcdir += Path.Sep;
|
||||
if (!newdir.EndsWith(Path.Sep)) newdir += Path.Sep;
|
||||
int i = 0;
|
||||
for (; i < files.Count; i++)
|
||||
File.CreateSymlink(files[i], files[i].Replace(srcdir, newdir));
|
||||
|
||||
@@ -7,14 +7,12 @@ public static class File
|
||||
public static bool Exists(string file) => System.IO.File.Exists(file);
|
||||
|
||||
// если файл не существует, создаёт файл, создаёт папки из его пути
|
||||
public static void Create(string file, bool delete_old = false)
|
||||
public static void Create(string file)
|
||||
{
|
||||
if (delete_old && File.Exists(file))
|
||||
File.Delete(file);
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
if (file.Contains("\\"))
|
||||
Directory.Create(file.Remove(file.LastIndexOf('\\')));
|
||||
if (file.Contains(Path.Sep))
|
||||
Directory.Create(file.Remove(file.LastIndexOf(Path.Sep)));
|
||||
using System.IO.FileStream stream = System.IO.File.Create(file);
|
||||
stream.Close();
|
||||
}
|
||||
@@ -64,7 +62,9 @@ public static class File
|
||||
Exists(file) ? System.IO.File.OpenRead(file) : throw new Exception($"file not found: <{file}>");
|
||||
public static System.IO.FileStream OpenWrite(string file)
|
||||
{
|
||||
File.Create(file, true);
|
||||
if (File.Exists(file))
|
||||
File.Delete(file);
|
||||
File.Create(file);
|
||||
return System.IO.File.Open(file, System.IO.FileMode.OpenOrCreate);
|
||||
}
|
||||
public static System.IO.FileStream OpenAppend(string file)
|
||||
@@ -75,8 +75,8 @@ public static class File
|
||||
|
||||
public static void CreateSymlink(string sourceName, string symlinkName)
|
||||
{
|
||||
if (symlinkName.Contains("\\"))
|
||||
Directory.Create(symlinkName.Remove(symlinkName.LastIndexOf('\\')));
|
||||
if (symlinkName.Contains(Path.Sep))
|
||||
Directory.Create(symlinkName.Remove(symlinkName.LastIndexOf(Path.Sep)));
|
||||
if (!Symlink.CreateSymbolicLink(symlinkName, sourceName, Symlink.SymlinkTarget.File))
|
||||
throw new InvalidOperationException($"some error occured while creating symlink\nFile.CreateSymlink({symlinkName}, {sourceName})");
|
||||
}
|
||||
|
||||
@@ -5,15 +5,6 @@
|
||||
//
|
||||
public static class OldFilework
|
||||
{
|
||||
// записывает текст в файл и закрывает файл
|
||||
/*public static void LogToFile(string logfile, string msg)
|
||||
{
|
||||
lock (new object())
|
||||
{
|
||||
File.AppendAllText(logfile, msg);
|
||||
}
|
||||
}*/
|
||||
|
||||
// чтение параметров из конфига
|
||||
public static string ReadFromConfig(string configfile, string key)
|
||||
{
|
||||
|
||||
@@ -2,15 +2,16 @@ namespace DTLib.Filesystem;
|
||||
|
||||
static public class Path
|
||||
{
|
||||
static public readonly char Sep = OperatingSystem.IsWindows() ? '\\' : '/';
|
||||
|
||||
public static string CorrectSeparator(string path)
|
||||
{
|
||||
if (System.IO.Path.PathSeparator == '\\')
|
||||
if (Sep == '\\')
|
||||
{
|
||||
if (path.Contains('/'))
|
||||
path = path.Replace('/', '\\');
|
||||
}
|
||||
else if (System.IO.Path.PathSeparator == '/')
|
||||
else if (Sep == '/')
|
||||
{
|
||||
if (path.Contains('\\'))
|
||||
path = path.Replace('\\', '/');
|
||||
|
||||
Reference in New Issue
Block a user