- Main Page
- Related Pages
- Modules
- Classes
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions

# MFileObject Class Reference

# OpenMaya - API module for common classes

This reference page is linked to from the following overview topics: File Translator Examples.

Search for all occurrences

## Detailed Description

Manipulate Unix filenames and search paths.

The MFileObject class implements an object that contains both a filename and a search path. The search path is specified by a single string in which multiple elements are separated by ':' characters. As well this string can contain Unix environment variables, specified as $VARNAME,

Filenames can be produced by the class by combining the path element with the filename element of the MFileObject. As well, methods are available to test for the existance of the files produced.

Examples:

  animExportUtil.cpp, animExportUtil.h, animImportExport.cpp, animImportExport.h, cgfxFindImage.cpp, cgfxShaderNode.cpp, filteredAsciiFile.cpp, hlslShader.cpp, lepTranslator.cpp, maTranslator.cpp, objExport.cpp, polyExporter.cpp, and polyExporter.h.

`#include <MFileObject.h>`

List of all members.

## Public Types
enum | MFileResolveMethod { kNone = (1<<0), kExact = (1<<1), kDirMap = (1<<2), kReferenceMappings = (1<<3), kRelative = (1<<4), kBaseName = (1<<5), kInputFile = kExact | kDirMap | kRelative | kBaseName, kInputReference = kInputFile | kReferenceMappings, kStrict = kExact | kDirMap }
| Options to be used when resolving a file path. More...
## Public Member Functions
| MFileObject ()
| Class constructor.
| MFileObject (const MFileObject &other)
| Copy constructor.
virtual | ~MFileObject ()
| Class destructor.
MFileObject & | operator= (const MFileObject &other)
| Assignment operator.
MStatus | setRawName (const MString &fileName)
| Set the unresolved filename element of the MFileObject instance.
MStatus | setRawPath (const MString &filePath)
| Set the unresolved path element of the MFileObject instance.
MStatus | setRawFullName (const MString &fullFileName)
| This method combines the functions of the setRawName and setRawPath methods in that it sets both the path and filename from the given name.
MStatus | overrideResolvedFullName (const MString &fullFileName)
| Normally when a raw file name is set, Maya will perform a series of operations on it in an attempt to resolve it to a valid file name.
MString | rawName () const
| Returns the unresolved filename element of the MFileObject.
MString | rawPath () const
| Returns the path element of the MFileObject with all environment variables unexpanded.
MString | rawFullName () const
| Returns the unresolved full file name (path plus filename) of the MFileObject with all environment variables unexpanded.
MString | expandedPath () const
| Returns the path element of the MFileObject with all environment variables expanded.
MString | expandedFullName () const
| Returns the first pathname of a file constructed from the path and filename elements.
MString | resolvedName () const
| Returns the resolved filename element of the MFileObject.
MString | resolvedPath () const
| Returns the resolved path element of the MFileObject.
MString | resolvedFullName () const
| Returns the first pathname of a file constructed from the path and filename elements.
unsigned int | pathCount ()
| Returns the number of paths in the path element of the MFileObject.
MString | ithPath (unsigned int index)
| Returns the indicated portion of the path element of the MFileObject.
MString | ithFullName (unsigned int index)
| Returns the pathname of a file constructed from the indicated portion of the path element and filename element.
bool | exists ()
| Checks to see if the file returned by the fullName method exists and is readable.
bool | exists (unsigned int index)
| Checks to see if the file constructed from the indicated portion of the path element and filename element exists and is readble.
bool | isSet () const
| Checks to see if both file and path elements of the MFileObject have been set.
void | setResolveMethod (MFileResolveMethod method)
| Set the steps that should be used to resolve this file path.
MFileResolveMethod | resolveMethod () const
| Returns the file-path resolution steps this object will use.
MStatus | setName (const MString &fileName)
| This method is obsolete.
MStatus | setFullName (const MString &fileName)
| This method is obsolete.
MString | name () const
| This method is obsolete.
MString | path () const
| This method is obsolete.
MString | fullName () const
| This method is obsolete.
## Static Public Member Functions
static bool | isAbsolutePath (const MString &fileName)
| Utility method which checks a file path string and determines if it represents an absolute file path.

## Member Enumeration Documentation

enum MFileResolveMethod

Search for all occurrences

Options to be used when resolving a file path.

Enumerator:

  kNone | (Default) The resolved path is simply the first path after expanding any environment variables. Will not check if this file actually exists. User must explicitly check MFileObject::exists() Search for all occurrences
  kExact | Checks if expanded paths exist. If paths are relative, assume it's relative to the current workspace (so check workspace current directory, file-rule directory and root directory Search for all occurrences
  kDirMap | Checks path against mappings defined with the dirmap command. Only for absolute paths. Search for all occurrences
  kReferenceMappings | Check path against any previously re-mapped reference locations. If kRelative/kBaseName are set, then even if we have an absolute path, convert to relative and/or baseName and look for them in directories provided to the missing reference dialog. Search for all occurrences
  kRelative | Strips away the project directory, and treats path as relative. Relative to the current workspace, that is. So look in the workspace current directory, file-rules directory and the root directory Search for all occurrences
  kBaseName | Strips away everything but the base file name and look in the current workspace. Search for all occurrences
  kInputFile | Default on file open and import. Search for all occurrences
  kInputReference | Default on file reference. Search for all occurrences
  kStrict | Equivalent to the file -strict flag. Search for all occurrences

## Constructor & Destructor Documentation

MFileObject | ( |  | ) |

Class constructor.

Create a new MFileObject that contains neither a path nor a filename.

MFileObject | ( | const MFileObject & | other | ) |

Copy constructor.

Create a new MFileObject instance and initialize it with the same path and filename as the given instance.

Parameters:

  [in] | other | The MFileObject to copy.

## Member Function Documentation

MFileObject & operator= | ( | const MFileObject & | other | ) |

Assignment operator.

Allows assignment between MFileObjects.

Parameters:

  [in] | other | Existing MFileObject to be assigned to this one.

Returns:
  Reference to this MFileObject instance.

MStatus setRawName | ( | const MString & | fileName | ) |

Search for all occurrences

Set the unresolved filename element of the MFileObject instance.

This name should not contain any '/' characters, it should indicate simply the name of a file. The directories in which this name will be searched for are specified by setRawPath.

Parameters:

  [in] | fileName | The filename to set.

Returns:
  MS::kSuccess

MStatus setRawPath | ( | const MString & | pathName | ) |

Search for all occurrences

Set the unresolved path element of the MFileObject instance.

This should contain a list of directories, each separated by a single ':' character. The pathnames can contain Unix environment variables in the form $VARNAME. These will be expanded when paths to actual filenames are constructed.

Note that if the specified pathName is relative, contains environment variables, or does not exist, the paths returned by MFileObject::resolvedPath() and MFileObject::expandedPath() may not match the rawPath. See the description of MFileObject::resolvedPath() and MFileObject::expandedPath() for more information.

Parameters:

  [in] | pathName | The path string.

Returns:
  MS::kSuccess

MStatus setRawFullName | ( | const MString & | fullFileName | ) |

Search for all occurrences

This method combines the functions of the setRawName and setRawPath methods in that it sets both the path and filename from the given name.

If any '/' characters appear in the given name then the path element of the MFileObject is set to everything in name up to, but not including the last '/'. The filename is set to the part of name after the final '/'.

If no '/' characters appear in the given name then the path element is set to "." and the filename is set to the given name.

Note that if the specified fullFileName is relative, contains environment variables, or does not exist, the full names returned by MFileObject::resolvedFullName() and MFileObject::expandedFullName() may not match the fullFileName. See the description of MFileObject::resolvedFullName() and MFileObject::expandedFullName() for more information.

Parameters:

  [in] | fullFileName | the string used to initialize the path and filename.

Returns:
  MS::kSuccess

Examples:
  cgfxFindImage.cpp, cgfxShaderNode.cpp, and hlslShader.cpp.

MStatus overrideResolvedFullName | ( | const MString & | fullFileName | ) |

Search for all occurrences

Normally when a raw file name is set, Maya will perform a series of operations on it in an attempt to resolve it to a valid file name.

This final resolved file name can be accessed through the MFileObject::resolvedName(), MFileObject::resolvedPath(), and MFileObject::resolvedFullFileName() methods and can be quite different from the originally specified raw file name.

This method will override the normal Maya path resolution process and explicitly set the resolved file name. This path does not have to be a valid file path, but if any '/' characters appear in the given name then the resolved path element of the MFileObject is set to everything in name up to, but not including the last '/'. The resolved filename is set to the part of name after the final '/'.

Once the resolved file name is set, it is only guaranteed to be retained in the MFileObject so long as the raw file path is not updated. Once MFileObject::setRawPath(), MFileObject::setRawName(), or MFileObject::setRawFullName() is called, the normal Maya path resolution process will be re-invoked and the resolved path and filename will be updated.

Parameters:

  [in] | fullFileName | the string used to override the path and filename.

Returns:
  MS::kSuccess

MString rawName | ( |  | ) | const

Search for all occurrences

Returns the unresolved filename element of the MFileObject.

Returns:
  The unresolved filename.

MString rawPath | ( |  | ) | const

Search for all occurrences

Returns the path element of the MFileObject with all environment variables unexpanded.

Returns:
  The path.

MString rawFullName | ( |  | ) | const

Search for all occurrences

Returns the unresolved full file name (path plus filename) of the MFileObject with all environment variables unexpanded.

Returns:
  The full, unresolved file path.

MString expandedPath | ( |  | ) | const

Search for all occurrences

Returns the path element of the MFileObject with all environment variables expanded.

After expanding environment variables Maya may perform additional modifications to the path in order to resolve it to a valid location on disk. This resolved path can be accessed through MFileObject::resolvedPath().

Returns:
  The expanded path.

MString expandedFullName | ( |  | ) | const

Search for all occurrences

Returns the first pathname of a file constructed from the path and filename elements.

All variables in the path element are expanded, and the first path (the part before the first ':' in the path) is prepended to the filename element to construct the fullName.

After expanding environment variables Maya may perform additional modifications to the full file name in order to resolve it to a valid location on disk. This resolved full file name can be accessed through MFileObject::resolvedFullName().

Returns:
  The expanded filename.

MString resolvedName | ( |  | ) | const

Search for all occurrences

Returns the resolved filename element of the MFileObject.

Returns:
  The resolved filename.

MString resolvedPath | ( |  | ) | const

Search for all occurrences

Returns the resolved path element of the MFileObject.

In order to build the resolved path, Maya first expands all environment variables and then may perform additional modifications, such as prepending directories to a relative path name, in order to resolve the path to a valid location on disk.

Returns:
  The resolved path.

Examples:
  cgfxFindImage.cpp, and hlslShader.cpp.

MString resolvedFullName | ( |  | ) | const

Search for all occurrences

Returns the first pathname of a file constructed from the path and filename elements.

All variables in the path element are expanded, and the first path (the part before the first ':' in the path) is prepended to the filename element. After expanding all environment variables Maya may then perform additional modifications, such as prepending directories to a relative path name, in order to resolve the path to a valid location on disk.

Returns:
  The full, resolved filename.

unsigned int pathCount | ( |  | ) |

Search for all occurrences

Returns the number of paths in the path element of the MFileObject.

This will be equal to one more than the number of ':' characters specified by the setRawPath method.

Returns:
  The number of path elements.

MString ithPath | ( | unsigned int | index | ) |

Search for all occurrences

Returns the indicated portion of the path element of the MFileObject.

All variables in the path element are expanded, and the portion indicated by the argument is extracted and returned.

Parameters:

  [in] | index | the index of the desired path portion.

Returns:
  The path element.

MString ithFullName | ( | unsigned int | index | ) |

Search for all occurrences

Returns the pathname of a file constructed from the indicated portion of the path element and filename element.

All variables in the path element are expanded, and the indicated path portion is prepended to the filename element to construct the fullName.

Parameters:

  [in] | index | the index of the desired path portion.

Returns:
  The pathname.

bool exists | ( |  | ) |

Search for all occurrences

Checks to see if the file returned by the fullName method exists and is readable.

Returns:
  true if the file exists and is readable, false otherwise.

bool exists | ( | unsigned int | index | ) |

Search for all occurrences

Checks to see if the file constructed from the indicated portion of the path element and filename element exists and is readble.

Parameters:

  [in] | index | Index of the path element to be used in searching for the file.

Returns:
  true if the file exists and is readable, false otherwise.

bool isSet | ( |  | ) | const

Search for all occurrences

Checks to see if both file and path elements of the MFileObject have been set.

Returns:
  true if both elements have been set, false otherwise.

void setResolveMethod | ( | MFileResolveMethod | method | ) |

Search for all occurrences

Set the steps that should be used to resolve this file path.

Parameters:

  [in] | method | Structure indicating how to resolve the file path.

MFileObject::MFileResolveMethod resolveMethod | ( |  | ) | const

Search for all occurrences

Returns the file-path resolution steps this object will use.

Returns:
  Resolution method

MStatus setName | ( | const MString & | fileName | ) |

Search for all occurrences

This method is obsolete.

Deprecated:
  Use the method MFileObject::setRawName instead.

Set the filename element of the MFileObject instance. This name should not contain any '/' characters, it should indicate simply the name of a file. The directories in which this name will be searched for are specified by setRawPath.

Parameters:

  [in] | fileName | The filename.

Returns:
  MS::kSuccess

MStatus setFullName | ( | const MString & | fileName | ) |

Search for all occurrences

This method is obsolete.

Deprecated:
  Use the method MFileObject::setRawFullName instead.

This method combines the functions of the setName and setRawPath methods in that it sets both the path and filename from the given name.

If any '/' characters appear in the given name then the path element of the MFileObject is set to everything in name up to, but not including the last '/'. The filename is set to the part of name after the final '/'.

If no '/' characters appear in the given name then the path element is set to "." and the filename is set to the given name.

Parameters:

  [in] | fileName | the string used to initialize the path and filename.

Returns:
  MS::kSuccess

MString name | ( |  | ) | const

Search for all occurrences

This method is obsolete.

Deprecated:
  Use the method MFileObject::resolvedName instead.

Returns the filename element of the MFileObject.

Returns:
  The resolved filename.

Examples:
  animExportUtil.cpp, animImportExport.cpp, maTranslator.cpp, and objExport.cpp.

MString path | ( |  | ) | const

Search for all occurrences

This method is obsolete.

Deprecated:
  Use the methods MFileObject::expandedPath or MFileObject::resolvedPath instead.

Returns the path element of the MFileObject with all environment variables expanded.

Returns:
  The expanded path.

Examples:
  cgfxShaderNode.cpp.

MString fullName | ( |  | ) | const

Search for all occurrences

This method is obsolete.

Deprecated:
  Use the methods MFileObject::expandedFullName or MFileObject::resolvedFullName instead.

Returns the first pathname of a file constructed from the path and filename elements. All variables in the path element are expanded, and the first path (the part before the first ':' in the path) is prepended to the filename element to construct the fullName.

Returns:
  The expanded filename.

Examples:
  animExportUtil.cpp, animImportExport.cpp, lepTranslator.cpp, maTranslator.cpp, objExport.cpp, and polyExporter.cpp.

bool isAbsolutePath | ( | const MString & | fileName | ) | `[static]`

Search for all occurrences

Utility method which checks a file path string and determines if it represents an absolute file path.

An absolute path can uniquely identify a directory or file.

Parameters:

  [in] | fileName | the string used to check if it is absolute

Returns:
  True if fileName is an absolute path

MFileObject MFileObject MFileObject MFileObject MFileObject MFileObject MFileObject MFileObject MFileObject MFileObject
MFileObject MFileObject MFileObject MFileObject MFileObject MFileObject MFileObject MFileObject MFileObject MFileObject