This utility class mainly contains static members. More...
#include <ms_fileutilities.hpp>
Public Member Functions | |
ms_fileutilities () | |
Default constructor. | |
void | findClose () |
Functions to search for all files that match a wildcard. | |
bool | findNext (std::string &fileName) |
Functions to search for all files that match a wildcard. | |
bool | findOpen (const std::string directory, const std::string wildcard) |
Functions to search for all files that match a wildcard. | |
unsigned long | getSARExtendedErrorCode () const |
err_sar | setAccessRights (const char *filename, const bool bWrite, const bool bExecute, const bool isFile, const ms_mascotoptions &Options, const bool avoid_reapply=false) |
Sets access rights for a file according to settings in mascot.dat . | |
Static Public Member Functions | |
static bool | compareXmlFiles (const std::string &filePath1, const std::string &filePath2, const std::string &schemaPath, const int flags, const std::vector< std::string > &ignoreElements, const std::vector< std::string > &ignoreAttributes, ms_errs &errs, std::string &differences, std::string &lhsOnly, std::string &rhsOnly) |
Compare 2 XML files. | |
static int | createDirectory (const std::string &directory, std::string &errorDirectory) |
Create a directory or directory tree. | |
static int | deleteDirectory (const std::string &directory, const bool bDeleteSubdirectories=true) |
Delete a directory or directory tree. | |
static bool | doesFileExist (const char *filename) |
Returns true if the specified file exists, false otherwise. | |
static std::string | findMascotDat (const char *szMascotDatFilename, ms_errs *err=NULL, const int timeoutSec=0) |
Returns a correct path to mascot.dat if it can be found in one of the default places. | |
static UINT64 | getFileSize (const char *filename, ms_errs *err=NULL) |
Returns the size of the file. | |
static time_t | getLastModificationTime (const char *filename, ms_errs *err=NULL) |
Returns the last file modification time. | |
static std::string | getMD5Sum (const std::string &str, const bool b32bitEncoding=true) |
Return an MD5 sum of a string. | |
static bool | isDirectory (const char *path) |
Determine if the passed path is a directory or a file. | |
static bool | isFileWritable (const char *filePath) |
static int | parseCommandLineArgumentString (const std::string &command, std::vector< std::string > &components) |
Split a command-line argument string into components. | |
static void | setLastModificationTime (const char *filename, time_t modificationTime, ms_errs *err=NULL) |
Sets the last file modification time. | |
static std::string | stripLastFolder (const std::string pathname) |
Returns a pathname without last token, i.e. makes "C:\myfolder" from "C:\myfolder\XXX". | |
This utility class mainly contains static members.
For static members, creating an instance of this class is not required.
Return status from parseCommandLineArgumentString().
Flags for the compareXmlFiles() function.
enum err_sar |
setAccessRights() return value.
ms_fileutilities | ( | ) |
Default constructor.
Creating an instance of this class is not required.
|
static |
Compare 2 XML files.
See Multiple return values in Perl, Java, Python and C#.
[in] | filePath1 | is the path for the first (or left) file. |
[in] | filePath2 | is the path for the first (or right) file. |
[in] | schemaPath | must be valid and must have space separated pairs of "namespace" "path_to_xsd". See the example in ms_mascotresfilebase::setXMLschemaFilePath. |
[in] | flags | is one or more ms_fileutilities::compareXMLFiles_flags bitwise OR'd together. |
[in] | ignoreElements | is a vector of element names for which the element values will be ignored. Any attributes and child elements for the specified elements will still be compared. The full path to the element should be specified, e.g. "<quantitationResults><peptideMatch><partner><xic><intensity>" See Using STL vector classes vectori, vectord and VectorString in Perl, Java, Python and C# |
[in] | ignoreAttributes | is a vector of string of attribute names to be ignored in the comparison. If a value contains an '=', then it will only be ignored if the attribute (in either file) is equal to the specified value. For example, 'minorVersion' would ignore all 'minorVersion' attributes, but 'minorVersion="2"' will only ignore if either side has a value of "2" See Using STL vector classes vectori, vectord and VectorString in Perl, Java, Python and C# |
[out] | errs | is used to return a list of any XML parsing errors |
[out] | differences | is used to return a list of attribute and value differences for elements that appear in both input files. |
[out] | lhsOnly | is used to return a list of elements that only appear in file1 |
[out] | rhsOnly | is used to return a list of elements that only appear in file2 |
|
static |
Create a directory or directory tree.
See Static functions in Perl, Java, Python and C#
See Multiple return values in Perl, Java, Python and C#.
[in] | directory | is the path of the directory to be created. |
[out] | errorDirectory | is the path of the first directory that it fails to create if the function fails. |
|
static |
Delete a directory or directory tree.
See Static functions in Perl, Java, Python and C#
Deletes the contents and subdirectories of a tree.
[in] | directory | is the path of the directory to be deleted. |
[in] | bDeleteSubdirectories | is a flag to specify if subdirectories should be deleted |
|
static |
Returns true if the specified file exists, false otherwise.
See Static functions in Perl, Java, Python and C#
filename | is the file to check |
void findClose | ( | ) |
Functions to search for all files that match a wildcard.
To use findOpen(), findNext() and findClose() :
These functions cannot currently be called from any language apart from C++
Do not call findOpen() for a second directory on any ms_fileutilities object until findClose() has been called for the first directory.
|
static |
Returns a correct path to mascot.dat
if it can be found in one of the default places.
See Static functions in Perl, Java, Python and C#
szMascotDatFilename | is an optional filename. If an empty string or a null pointer is passed, default values are used depending on the platform. |
err | is a pointer to an error object which can be used to return detailed errors. See Passing objects to functions in Perl, Java, Python and C# |
timeout | is the time in seconds to look for the file. If the file is being edited, it may not exist for a short period, so rather than erroring, this function will wait. |
bool findNext | ( | std::string & | fileName | ) |
Functions to search for all files that match a wildcard.
To use findOpen(), findNext() and findClose() :
These functions cannot currently be called from any language apart from C++
Do not call findOpen() for a second directory on any ms_fileutilities object until findClose() has been called for the first directory.
fileName | is the name of the found file. |
bool findOpen | ( | const std::string | directory, |
const std::string | wildcard | ||
) |
Functions to search for all files that match a wildcard.
To use findOpen(), findNext() and findClose() :
These functions cannot currently be called from any language apart from C++
Do not call findOpen() for a second directory on any ms_fileutilities object until findClose() has been called for the first directory.
directory | is the directory to find files. |
wildcard | is a wildcard pattern. For example "*.dat". |
|
static |
Returns the size of the file.
See Static functions in Perl, Java, Python and C#
filename | is the relative or absolute path to the file |
err | is a pointer to an optional error object which can be used to return detailed errors. See Passing objects to functions in Perl, Java, Python and C# |
|
static |
Returns the last file modification time.
See Static functions in Perl, Java, Python and C#
filename | is the relative or absolute path to the file |
err | is a pointer to an optional error object which can be used to return detailed errors. See Passing objects to functions in Perl, Java, Python and C# |
|
static |
Return an MD5 sum of a string.
See Static functions in Perl, Java, Python and C#
Useful for creating a unique filename from, for example, a long pathname or a set of options.
For 64 bit encoding the returned text is base 64 Encoded with a URL and Filename Safe Alphabet; see http://tools.ietf.org/html/rfc3548#section-4.
For 32 bit encoding, the returned text is base 32 bit encoded (except that lower case rather than upper case letters are used); see http://tools.ietf.org/html/rfc3548#section-5.
str | is the string (of any length) than needs to be converted. If a zero length string is passed, a zero length string will be returned. |
b32bitEncoding | should be set to true to give 32 bit encoded string (essential for file systems where an upper case filename and a lower case filename are considered to be the same. If this value is false, then 64 bit encoding is used. |
unsigned long getSARExtendedErrorCode | ( | ) | const |
This can be called if setAccessRights() returns one of the following:
The value will be zero for any other errors and is used to return an error code for Windows only.
|
static |
Determine if the passed path is a directory or a file.
See Static functions in Perl, Java, Python and C#
path | Path to a directory or file |
|
static |
See Static functions in Perl, Java, Python and C#
filePath | is the file to check |
|
static |
Split a command-line argument string into components.
A command-line argument string consists of an executable name or filepath followed by a list of zero or more arguments. The executable and arguments are separated by one or more whitespace character. Here are some examples at increasing levels of complexity:
dir cd "C:/Program Files" "C:/Program Files/Perl64/bin/perl.exe" C:/inetpub/mascot/bin/dbman_download.pl SwissProt
Any of the components can include spaces, including the executable name; in this case, the component with spaces must be delimited by quotes ("). If the command string does include quotes, the quotes must be balanced, in the sense that an opening quote must follow a closing quote. Further, an opening quote must be preceded by whitespace and a closing quote followed by whitespace. Otherwise the method indicates a syntax error (as such strings are ambiguous). This means the following are all syntax errors and cause the method to return a non-OK status:
"dir cd"C:/Program Files" "C:/Program Files/Perl64/bin/perl.exe"C:/inetpub/mascot/bin/dbman_download.pl SwissProt
Note that any of the components, including the executable name, can be the empty string, e.g.
dir "" "" SwissProt
You need to check each item in components before processing further, even if the command string is parsed without error.
If you pass in the empty string in command, you will get an OK status and an empty vector out.
This method does not interpret the components in any way. In particular, it does not check that the first component is an executable filepath or that it exists on disk.
command | The command-line style string. |
components | Components parsed from command, with quotes stripped out. |
ms_fileutilities::err_sar setAccessRights | ( | const char * | filename, |
const bool | bWrite, | ||
const bool | bExecute, | ||
const bool | bIsFile, | ||
const ms_mascotoptions & | Options, | ||
const bool | avoid_reapply = false |
||
) |
Sets access rights for a file according to settings in mascot.dat
.
See Using enumerated values and static const ints in Perl, Java, Python and C#.
The bWrite flag is ignored.
The bExecute flag is ignored.
The bIsFile parameter is ignored.
If the filename passed is for a file rather than a directory, then chmod is called with the following flags:
If the filename passed is for a directory, then chmod is called with the flags above unless ms_mascotoptions::getUnixDirPerm() is defined, in which case the permission used are defined by that entry in mascot.dat
.
If ms_mascotoptions::getUnixWebUserGroup() is not -1 and is not -2, then a chown will be performed using the group id specified by ms_mascotoptions::getUnixWebUserGroup().
filename | is the name of the file, or memory mapped object that will be changed by this function. |
bWrite | should be set to true if the file should be set to be writeable by the group and others. |
bExecute | should be set to true for executable files or directories. |
bIsFile | should be set to true for files and directories, and false for for memory mapped file objects. |
Options | is the options section of mascot.dat . |
avoid_reapply | should be set to true if it should avoid applying the rights if the files already have the desired access configuration. Windows only, false by default. |
|
static |
Sets the last file modification time.
See Static functions in Perl, Java, Python and C#
filename | is the relative or absolute path to the file |
modificationTime | is the time to be applied as the file's last write time |
err | is a pointer to an optional error object which can be used to return detailed errors. See Passing objects to functions in Perl, Java, Python and C# |
|
static |
Returns a pathname without last token, i.e. makes "C:\myfolder" from "C:\myfolder\XXX".
See Static functions in Perl, Java, Python and C#
pathname | of the filepath to strip. |