14 [
Obsolete(
"Use FileIO.MakeDirectory instead")]
20 if (
FileIO.FileExists(absoluteDirectory))
26 if (
FileIO.FileExists(absoluteDirectory))
29 array<string> pieces = {};
32 if (pieces.Count() < 2)
34 Print(
"Cannot create directory " + absoluteDirectory +
"; not enough directories",
LogLevel.DEBUG);
38 string path = pieces[0];
39 for (
int i = 1, count = pieces.Count(); i < count; i++)
48 Print(
"Cannot create directory " + absoluteDirectory +
"; blocked at " +
path,
LogLevel.DEBUG);
61 static array<string>
FindFiles(
string directoryPath,
string extension)
63 array<string> result = {};
64 FileIO.FindFiles(result.Insert, directoryPath, extension);
75 static bool Copy(
string source,
string destination,
bool overwrite =
true)
86 if (!
FilePath.IsAbsolutePath(destination) && !Workbench.GetAbsolutePath(destination, absolutePath,
false))
88 Print(
"Cannot get destination's absolute file path - " + destination,
LogLevel.WARNING);
93 if (!overwrite &&
FileIO.FileExists(destination))
95 Print(
"Not allowed to overwrite file - " + destination,
LogLevel.WARNING);
113 static bool CopyFile(
string sourceFile,
string destinationFile)
115 if (!
FileIO.FileExists(sourceFile))
118 if (
FileIO.CopyFile(sourceFile, destinationFile))
121 if (!
FileIO.MakeDirectory(
FilePath.StripFileName(destinationFile)))
124 return FileIO.CopyFile(sourceFile, destinationFile);
132 static bool CopyDirectory(
string sourceDirectory,
string destinationDirectory)
135 if (!Workbench.GetAbsolutePath(sourceDirectory, sourceDirectory,
true))
141 if (!Workbench.GetAbsolutePath(destinationDirectory, destinationDirectory,
false))
143 Print(
"Wrong destinationDirectory provided",
LogLevel.WARNING);
147 if (!
FileIO.FileExists(sourceDirectory))
153 if (!
FileIO.FileExists(destinationDirectory))
155 Print(
"Wrong destinationDirectory provided",
LogLevel.WARNING);
161 if (!directoryContent)
163 Print(
"Cannot get files from directory " + sourceDirectory,
LogLevel.WARNING);
167 if (directoryContent.IsEmpty())
169 if (
FileIO.FileExists(destinationDirectory))
172 return FileIO.MakeDirectory(destinationDirectory);
175 if (!
FileIO.MakeDirectory(destinationDirectory))
177 Print(
"Cannot create " + destinationDirectory,
LogLevel.ERROR);
183 int sourceDirectoryLength = sourceDirectory.Length();
184 array<string> isDirCheck = {};
185 foreach (SCR_FileInfo fileInfo : directoryContent)
187 string newAbsPath = destinationDirectory + fileInfo.m_sFilePath.Substring(sourceDirectoryLength, fileInfo.m_sFilePath.Length() - sourceDirectoryLength);
189 if ((fileInfo.m_eAttributes |
FileAttribute.DIRECTORY) == fileInfo.m_eAttributes)
191 if (!
FileIO.MakeDirectory(fileInfo.m_sFilePath))
202 string newAbsFileDir =
FilePath.StripFileName(newAbsPath);
203 if (!
FileIO.MakeDirectory(newAbsFileDir))
209 if (!
FileIO.CopyFile(fileInfo.m_sFilePath, newAbsPath))
211 PrintFormat(
"Cannot copy '%1' to '%2'", fileInfo.m_sFilePath, newAbsPath, level:
LogLevel.ERROR);
224 static bool RenameFile(
string sourceFile,
string destinationFile)
226 return FileIO.CopyFile(sourceFile, destinationFile) &&
FileIO.DeleteFile(sourceFile);
246 fileHandle.Read(result, -1);
261 array<ref SCR_FileInfo> result = SCR_ArrayHelperRefT<SCR_FileInfo>.GetCopy(
FOUND_FILEINFOS);
284 array<string> result = {};
285 while (fileHandle.ReadLine(lineContent) > -1)
287 result.Insert(lineContent);
310 int linesCountMinusOne = lines.Count() - 1;
311 if (linesCountMinusOne == -1)
313 fileHandle.Write(
string.Empty);
317 foreach (
int lineNumber,
string line : lines)
319 if (lineNumber < linesCountMinusOne)
320 fileHandle.WriteLine(line);
324 fileHandle.Write(lines[linesCountMinusOne]);
340 if (!
FileIO.FileExists(filePath))
350 int linesCountMinusOne = lines.Count() - 1;
351 if (linesCountMinusOne == -1)
353 fileHandle.Write(
string.Empty);
358 fileHandle.Write(
"\n");
360 foreach (
int lineNumber,
string line : lines)
362 if (lineNumber < linesCountMinusOne)
363 fileHandle.WriteLine(line);
367 fileHandle.Write(lines[linesCountMinusOne]);
384 if (fileName.EndsWith(
"."))
387 if (fileName.EndsWith(
" "))
391 string forbiddenCharacters;
397 for (
int i, len = forbiddenCharacters.Length(); i < len; i++)
399 if (fileName.Contains(forbiddenCharacters[i]))
412 string forbiddenCharacters;
419 fileName =
FilePath.StripPath(fileName);
422 fileName.TrimInPlace();
423 if (fileName.IsEmpty())
428 int originalLength = fileName.Length();
429 int properLength = originalLength;
430 string lastChar = fileName[properLength - 1];
432 while (lastChar ==
"." || lastChar ==
" " || lastChar ==
"\t")
435 if (properLength < 1)
438 lastChar = fileName[properLength - 1];
441 if (properLength < 1)
444 if (properLength != originalLength)
445 fileName = fileName.Substring(0, properLength);
448 fileName.TrimInPlace();
471 SCR_FileInfo fileInfo =
new SCR_FileInfo();
472 fileInfo.m_sFilePath = fileName;
473 fileInfo.m_eAttributes = attributes;
474 fileInfo.m_sFileSystem = filesystem;
484 return rn.Substring(0, rn.IndexOf(
"}") + 1) +
FilePath.StripPath(rn.GetPath());
class RestAPIHelper< JsonApiStruct T > content
FileAttribute m_eAttributes
class SCR_FileIOHelper m_sFilePath
static bool CopyDirectory(string sourceDirectory, string destinationDirectory)
static bool AppendFileContent(string filePath, notnull array< string > lines)
static bool CreateDirectory(string absoluteDirectory)
static bool CopyFile(string sourceFile, string destinationFile)
static string GetFileStringContent(string filePath, bool printWarning=true)
static const string FORBIDDEN_FILENAME_CHARS_LINUX
static array< string > FindFiles(string directoryPath, string extension)
static bool RenameFile(string sourceFile, string destinationFile)
static string GetShortResourceName(ResourceName rn)
static const string PATH_DELIMITER
static string SanitiseFileName(string fileName)
static const ref array< ref SCR_FileInfo > FOUND_FILEINFOS
static bool WriteFileContent(string filePath, notnull array< string > lines)
static array< ref SCR_FileInfo > GetDirectoryContent(string directory, string extension="")
static bool IsValidFileName(string fileName)
static array< string > ReadFileContent(string filePath, bool printWarning=true)
static const string FORBIDDEN_FILENAME_CHARS_WINDOWS
static bool Copy(string source, string destination, bool overwrite=true)
static void FindFilesCallbackMethod(string fileName, FileAttribute attributes=0, string filesystem=string.Empty)
static bool IsWindowsBased()
static string Filter(string input, string characters, bool useCharactersAsBlacklist=false)
static string ReplaceRecursive(string input, string sample, string replacement)
static bool IsEmptyOrWhiteSpace(string input)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
FileMode
Mode for opening file. See FileSystem::Open.
FileAttribute
File attributes. See FileDescription.