Xmipp
v3.23.11-Nereus
|
#include <xmipp_filename.h>
Public Member Functions | |
Filename constructors | |
FileName () | |
FileName (const String &str) | |
FileName (const char *str) | |
FileName & | operator= (const FileName &op) |
FileName (const FileName &fn) | |
FileName (const char *str, int no, const String &ext="") | |
FileName (const char *str, const String &ext) | |
FileName (const String &str, const String &ext) | |
Composing/Decomposing the filename | |
String | getString () const |
bool | isEmpty () const |
void | compose (const String &str, const size_t no, const String &ext="") |
void | compose (const size_t no, const String &str) |
void | compose (size_t no, const String &str, const String &ext) |
void | compose (const String &blockName, const String &str) |
void | composeBlock (const String &blockName, size_t no, const String &str, const String &ext="") |
bool | isInStack () const |
void | decompose (size_t &no, String &str) const |
FileName | getDecomposedFileName () const |
FileName | getRoot () const |
FileName | getBaseName () const |
int | getNumber () const |
size_t | getPrefixNumber (size_t pos=0) const |
FileName | getDir () const |
String | getExtension () const |
String | getFileFormat () const |
bool | hasImageExtension () const |
bool | hasStackExtension () const |
bool | hasVolumeExtension () const |
bool | hasMetadataExtension () const |
size_t | getFileSize () const |
String | getBlockName () const |
FileName | removePrefixNumber () const |
FileName | removeBlockName () const |
FileName | removeAllPrefixes () const |
void | initRandom (int length) |
void | initUniqueName (const char *templateStr="xmippTemp_XXXXXX", const String &fnDir="") |
Filename utilities | |
FileName | toLowercase () const |
FileName | toUppercase () const |
bool | contains (const String &str) const |
FileName | beforeFirstOf (const String &str) const |
FileName | beforeLastOf (const String &str) const |
FileName | afterFirstOf (const String &str) const |
FileName | afterLastOf (const String &str) const |
FileName | addPrefix (const String &prefix) const |
FileName | addExtension (const String &ext) const |
FileName | withoutExtension () const |
FileName | withoutRoot () const |
FileName | insertBeforeExtension (const String &str) const |
FileName | removeExtension (const String &ext) const |
FileName | removeLastExtension () const |
FileName | removeFilename () const |
FileName | removeAllExtensions () const |
FileName | removeFileFormat () const |
bool | isMetaData (bool failIfNotExists=true) const |
bool | isStar1 (bool failIfNotExists) const |
FileName | replaceSubstring (const String &subOld, const String &subNew) const |
FileName | replaceCharacter (char oldChar, char newChar) const |
FileName | replaceExtension (const String &newExt) const |
FileName | removeSubstring (const String &sub) const |
FileName | removeUntilPrefix (const String &prefix) const |
FileName | removeDirectories (int keep=0) const |
void | copyFile (const FileName &target) const |
bool | exists () const |
void | deleteFile () const |
bool | existsTrim () const |
bool | isDir () const |
void | getFiles (std::vector< FileName > &files) const |
void | waitUntilStableSize (size_t time_step=250000) |
void | createEmptyFile (size_t size, size_t block_size=102400) |
void | createEmptyFileWithGivenLength (size_t length=0) const |
int | makePath (mode_t mode=0755) const |
void | assertExists () |
Filenames.
This class allows you a lot of usual and common manipulations with filenames. See filename conventions for a detailed explanation of the Filenames dealed here, although most of the functions work with the more general model "name.extension"
Definition at line 65 of file xmipp_filename.h.
|
inline |
Empty constructor
The empty constructor is inherited from the string class, so an empty FileName is equal to "".
Definition at line 80 of file xmipp_filename.h.
|
inline |
Constructor from string
The constructor from a string allows building complex expressions based on the string class. Notice that in the following example the type casting to string is very important, if not, the operation is just a pointer movement instead of a string concatenation.
Definition at line 94 of file xmipp_filename.h.
|
inline |
Constructor from char*
Definition at line 99 of file xmipp_filename.h.
|
inline |
Copy constructor
Definition at line 111 of file xmipp_filename.h.
|
inline |
Constructor from root, number and extension
The number and extension are optional.
Definition at line 124 of file xmipp_filename.h.
|
inline |
Constructor from root and extension
None of the parameters is optional
Definition at line 137 of file xmipp_filename.h.
Constructor from root and extension
None of the parameters is optional
Definition at line 148 of file xmipp_filename.h.
Add extension at the end.
The "." is added. If the input extension is "" then the same name is returned, with nothing added.
Definition at line 332 of file xmipp_filename.cpp.
Add string at the beginning
If there is a path then the prefix is added after the path.
Definition at line 324 of file xmipp_filename.cpp.
Return substring after first instance of argument (as in Bsoft)
Definition at line 212 of file xmipp_filename.cpp.
Return substring after last instance of argument (as in Bsoft)
Definition at line 220 of file xmipp_filename.cpp.
void FileName::assertExists | ( | ) |
This function raised an ERROR if the filename if not empty and if the corresponding file does not exist. This may be useful to have a better (killing) control on (mpi-regulated) jobs
This function is not ported to Python.
Definition at line 840 of file xmipp_filename.cpp.
Return substring before first instance of argument (as in Bsoft)
Definition at line 196 of file xmipp_filename.cpp.
Return substring before last instance of argument (as in Bsoft)
Definition at line 204 of file xmipp_filename.cpp.
Compose from root, number and extension
Definition at line 52 of file xmipp_filename.cpp.
void FileName::compose | ( | const size_t | no, |
const String & | str | ||
) |
Prefix with number . Mainly for selfiles
Definition at line 68 of file xmipp_filename.cpp.
Prefix with number and extension .
Definition at line 92 of file xmipp_filename.cpp.
Prefix with string (blockname) .
Definition at line 105 of file xmipp_filename.cpp.
void FileName::composeBlock | ( | const String & | blockName, |
size_t | no, | ||
const String & | str, | ||
const String & | ext = "" |
||
) |
Constructor: string, number, rootfilename and extension: mainly for numered metadata blocks..
Definition at line 114 of file xmipp_filename.cpp.
bool FileName::contains | ( | const String & | str | ) | const |
Check whether the filename contains the argument substring
Definition at line 189 of file xmipp_filename.cpp.
void FileName::copyFile | ( | const FileName & | target | ) | const |
void FileName::createEmptyFile | ( | size_t | size, |
size_t | block_size = 102400 |
||
) |
Write a zero filled file with the desired size.
The file is written by blocks to speed up, you can modify the block size. An exception is thrown if any error happens
Definition at line 752 of file xmipp_filename.cpp.
void FileName::createEmptyFileWithGivenLength | ( | size_t | length = 0 | ) | const |
Create empty file with a given length.
Definition at line 768 of file xmipp_filename.cpp.
void FileName::decompose | ( | size_t & | no, |
String & | str | ||
) | const |
Decompose filenames with . Mainly from selfiles
Definition at line 128 of file xmipp_filename.cpp.
void FileName::deleteFile | ( | ) | const |
Delete the file if exists
Definition at line 670 of file xmipp_filename.cpp.
bool FileName::exists | ( | ) | const |
True if the filename exists, check from current directory if is relative
Definition at line 665 of file xmipp_filename.cpp.
bool FileName::existsTrim | ( | ) | const |
True if the file exists in the current directory Remove leading xx@ and tailing :xx
Definition at line 677 of file xmipp_filename.cpp.
FileName FileName::getBaseName | ( | ) | const |
Get the base name from a filename
Definition at line 227 of file xmipp_filename.cpp.
String FileName::getBlockName | ( | ) | const |
FileName FileName::getDecomposedFileName | ( | ) | const |
Get decomposed filename from filenames with . Mainly from selfiles
Definition at line 147 of file xmipp_filename.cpp.
FileName FileName::getDir | ( | ) | const |
Definition at line 235 of file xmipp_filename.cpp.
String FileName::getExtension | ( | ) | const |
Get the last extension from filename
The extension is returned without the dot. If there is no extension "" is returned.
Definition at line 242 of file xmipp_filename.cpp.
String FileName::getFileFormat | ( | ) | const |
Get image format identifier
Definition at line 396 of file xmipp_filename.cpp.
void FileName::getFiles | ( | std::vector< FileName > & | files | ) | const |
Return the list of files if this filename is a directory
Definition at line 697 of file xmipp_filename.cpp.
size_t FileName::getFileSize | ( | ) | const |
Get the size of the file.
Definition at line 414 of file xmipp_filename.cpp.
int FileName::getNumber | ( | ) | const |
Get the number from a filename
If there is no number a -1 is returned.
Definition at line 447 of file xmipp_filename.cpp.
size_t FileName::getPrefixNumber | ( | size_t | pos = 0 | ) | const |
Get the number from a stack filename
If there is no number a 0 is returned.
Definition at line 466 of file xmipp_filename.cpp.
FileName FileName::getRoot | ( | ) | const |
Get the root from a filename
Definition at line 157 of file xmipp_filename.cpp.
|
inline |
Convert to String
Definition at line 158 of file xmipp_filename.h.
bool FileName::hasImageExtension | ( | ) | const |
True if the extension of this filename is of an image type
Definition at line 256 of file xmipp_filename.cpp.
bool FileName::hasMetadataExtension | ( | ) | const |
True if the extension of this filename is of a metadata file
Definition at line 283 of file xmipp_filename.cpp.
bool FileName::hasStackExtension | ( | ) | const |
True if the extension of this filename is of a stack type
Definition at line 266 of file xmipp_filename.cpp.
bool FileName::hasVolumeExtension | ( | ) | const |
True if the extension of this filename is of a stack type
Definition at line 275 of file xmipp_filename.cpp.
void FileName::initRandom | ( | int | length | ) |
Random name
Generate a random name of the desired length.
Definition at line 292 of file xmipp_filename.cpp.
void FileName::initUniqueName | ( | const char * | templateStr = "xmippTemp_XXXXXX" , |
const String & | fnDir = "" |
||
) |
Unique name
Generate a unique name replacing each 'X' with a character from the portable filename character set. The characters are chosen such that the resulting name does not duplicate the name of an existing file.
Definition at line 301 of file xmipp_filename.cpp.
Insert before first extension
If there is no extension, the insertion is performed at the end.
Definition at line 358 of file xmipp_filename.cpp.
bool FileName::isDir | ( | ) | const |
|
inline |
True if the FileName has an empty value ""
Definition at line 165 of file xmipp_filename.h.
bool FileName::isInStack | ( | ) | const |
True if this filename belongs to a stack
Definition at line 122 of file xmipp_filename.cpp.
bool FileName::isMetaData | ( | bool | failIfNotExists = true | ) | const |
Is this file a MetaData file? Returns true if the get_file_format extension == "sel", "doc" or "xmd" Otherwise, the file is opened and checked for the occurrence of "XMIPP_3 *" in its first line
Definition at line 556 of file xmipp_filename.cpp.
bool FileName::isStar1 | ( | bool | failIfNotExists | ) | const |
True if it is a Star 1 file.
Definition at line 576 of file xmipp_filename.cpp.
int FileName::makePath | ( | mode_t | mode = 0755 | ) | const |
makePath - ensure all directories in path exist Algorithm takes the pessimistic view and works top-down to ensure each directory in path exists, rather than optimistically creating the last element and working backwards. Return null if fails
Definition at line 811 of file xmipp_filename.cpp.
Assignment constructor
Definition at line 104 of file xmipp_filename.h.
FileName FileName::removeAllExtensions | ( | ) | const |
Remove all extensions
Definition at line 382 of file xmipp_filename.cpp.
FileName FileName::removeAllPrefixes | ( | ) | const |
Remove blockName or slice number from filename
Definition at line 548 of file xmipp_filename.cpp.
FileName FileName::removeBlockName | ( | ) | const |
FileName FileName::removeDirectories | ( | int | keep = 0 | ) | const |
Remove all directories
Or if keep>0, then keep the lowest keep directories
Definition at line 641 of file xmipp_filename.cpp.
Remove a certain extension
It doesn't matter if there are several extensions and the one to be removed is in the middle. If the given extension is not present in the filename nothing is done.
Definition at line 366 of file xmipp_filename.cpp.
FileName FileName::removeFileFormat | ( | ) | const |
Remove file format
Definition at line 435 of file xmipp_filename.cpp.
FileName FileName::removeFilename | ( | ) | const |
Extract the directory portion from a filename string (e.g. /foo/bar.txt -> /foo).
Definition at line 390 of file xmipp_filename.cpp.
FileName FileName::removeLastExtension | ( | ) | const |
Definition at line 374 of file xmipp_filename.cpp.
FileName FileName::removePrefixNumber | ( | ) | const |
Remove leading number from filename
Definition at line 531 of file xmipp_filename.cpp.
Remove a substring from the filename
If the substring is not present the same FileName is returned, if it is there the substring is removed. It is equivalent to replaceSubstring(sub, "");
Definition at line 625 of file xmipp_filename.cpp.
Remove until prefix
Remove the starting string until the given prefix, inclusively. For instance /usr/local/data/ctf-image00001.fft with ctf- yields image00001.fft. If the prefix is not found nothing is done.
Definition at line 631 of file xmipp_filename.cpp.
FileName FileName::replaceCharacter | ( | char | oldChar, |
char | newChar | ||
) | const |
Replace all occurrences of a character by another character
Definition at line 611 of file xmipp_filename.cpp.
Substitute last extension by a new one
Definition at line 619 of file xmipp_filename.cpp.
Replace a the first occurrence of substring 'subOld' by 'subNew' If 'subOld' not present, not changes are done. The search is done from left to right
Definition at line 599 of file xmipp_filename.cpp.
FileName FileName::toLowercase | ( | ) | const |
Change all characters for lowercases
Definition at line 171 of file xmipp_filename.cpp.
FileName FileName::toUppercase | ( | ) | const |
Change all characters for uppercases
Definition at line 180 of file xmipp_filename.cpp.
void FileName::waitUntilStableSize | ( | size_t | time_step = 250000 | ) |
Waits until the given filename has a stable size
The stable size is defined as having the same size within two samples separated by time_step (microsecs).
An exception is throw if the file exists but its size cannot be stated.
Definition at line 723 of file xmipp_filename.cpp.
FileName FileName::withoutExtension | ( | ) | const |
Remove last extension, if any
Definition at line 345 of file xmipp_filename.cpp.
FileName FileName::withoutRoot | ( | ) | const |
Remove the root
Definition at line 352 of file xmipp_filename.cpp.