Path.CorrectString
This commit is contained in:
parent
be9f61329e
commit
5c2638e221
@ -107,7 +107,7 @@ public static class Directory
|
||||
}
|
||||
|
||||
// copies directory with symlinks instead of files
|
||||
public static int SymCopy(string srcdir, string newdir)
|
||||
/*public static int SymCopy(string srcdir, string newdir)
|
||||
{
|
||||
List<string> files = GetAllFiles(srcdir);
|
||||
if (!srcdir.EndsWith(Путь.Разд)) srcdir += Путь.Разд;
|
||||
@ -116,5 +116,5 @@ public static class Directory
|
||||
for (; i < files.Count; i++)
|
||||
File.CreateSymlink(files[i], files[i].Replace(srcdir, newdir));
|
||||
return i;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@ -55,8 +55,10 @@ public class File
|
||||
|
||||
public static void Delete(string path) => System.IO.File.Delete(path);
|
||||
|
||||
public void Delete(string path)
|
||||
public static void Copy(string srcPath, string newPath, bool replace = false)
|
||||
{
|
||||
|
||||
System.IO.File.Copy(srcPath, newPath, replace);
|
||||
}
|
||||
|
||||
// public void Delete(string path)
|
||||
}
|
||||
@ -36,4 +36,55 @@ public static class Path
|
||||
if (path.Contains(".."))
|
||||
throw new Exception($"path <{path}> uses <..>, that's not allowed");
|
||||
}
|
||||
|
||||
/// Replaces restricted characters in string
|
||||
public static string CorrectString(string str)
|
||||
{
|
||||
#if NETSTANDARD2_1 || NET6_0 || NET7_0 || NET8_0
|
||||
var a = str.AsSpan();
|
||||
#else
|
||||
var a = str.ToArray();
|
||||
#endif
|
||||
char[] r = new char[a.Length];
|
||||
for (int i = 0; i < a.Length; i++)
|
||||
{
|
||||
switch (a[i])
|
||||
{
|
||||
case '/':
|
||||
case '\\':
|
||||
case ':':
|
||||
case ';':
|
||||
r[i] = '-';
|
||||
break;
|
||||
case '\n':
|
||||
case '\r':
|
||||
case ' ':
|
||||
case '#':
|
||||
case '%':
|
||||
case '&':
|
||||
case '{':
|
||||
case '}':
|
||||
case '<':
|
||||
case '>':
|
||||
case '*':
|
||||
case '?':
|
||||
case '$':
|
||||
case '!':
|
||||
case '\'':
|
||||
case '"':
|
||||
case '@':
|
||||
case '+':
|
||||
case '`':
|
||||
case '|':
|
||||
case '=':
|
||||
r[i] = '_';
|
||||
break;
|
||||
default:
|
||||
r[i] = a[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new string(r);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user