About
Filename is a special class to handle filenames and paths. It is used to easily construct and edit paths, filenames and suffixes. It also allows to open dialogs to select files and directories.
- Warning
- To handle files with the MAXON API see also Url Manual.
- Note
- To convert a Filname to a maxon::Url use MaxonConvert().
Access
Filename objects can be created on demand or can be obtained from other entities.
To retrieve and modify Filename objects stored in a BaseContainer respectively use:
See also BaseContainer Manual.
To retrieve and modify Filename objects stored in a GeData object (GeData type is DA_FILENAME) respectively use:
See also GeData Manual.
Important paths are obtained from:
@ ALEMBIC_PATH
Definition: Oalembicgenerator.h:6
Definition: c4d_baseobject.h:225
Definition: lib_description.h:330
String GetString(void) const
Definition: c4d_gedata.h:83
const Filename & GetFilename(void) const
Definition: c4d_gedata.h:475
#define Oalembicgenerator
Alembic generator.
Definition: ge_prepass.h:1141
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:210
const char * doc
Definition: pyerrors.h:226
Combine
A Filename can be constructed with basic operators:
- Note
- Only the last part (typically the file) of the given Filename is added.
const Filename fullFilePath = selectFolder +
"cube.c4d";
else
Manages file and path names.
Definition: c4d_file.h:94
Bool FileSelect(FILESELECTTYPE type, FILESELECT flags, const maxon::String &title, const maxon::String &force_suffix=maxon::String())
return OK
Definition: apibase.h:2667
@ DIRECTORY
Folder selection dialog.
Bool GeFExist(const Filename &name, Bool isdir=false)
if (bitmap == nullptr)
Bool ShowBitmap(const Filename &fn)
Definition: ge_autoptr.h:37
@ OK
Image loaded/created.
const Filename GeGetPluginPath(void)
Copy
A Filename object can easily be copied:
Properties
String
The content of a Filename object can be represented by a String:
See also String Manual (Classic).
const String filenameString = selectedFile.GetString();
Definition: c4d_string.h:39
File and Directory
A filename may be composed of a directory part and a file part. Each part can be edited independently:
const String directory = selectedFile.GetDirectory().GetString();
const char const char const char * file
Definition: object.h:439
Suffix
Part of the filename may also be the file suffix. This suffix can be edited separately:
if (selectedFile.CheckSuffix("c4d"_s))
else
It is possible to get the suffix for a given image file type:
Filename GeFilterSetSuffix(const Filename &name, Int32 id)
#define FILTER_JPG
JPEG.
Definition: ge_prepass.h:187
Memory Mode
The memory mode allows to perform read and write operations on a memory block instead of a file on the hard drive. This is typically used to encrypt or compress the resulting data.
if (mfs == nullptr)
void* data = nullptr;
hyperFile->WriteInt32(123);
hyperFile->WriteString("foo"_s);
hyperFile->WriteString("bar"_s);
hyperFile->WriteInt32(456);
hyperFile->Close();
mfs->GetData(data,
size,
false);
void SetMemoryWriteMode(MemoryFileStruct *mfs)
Py_ssize_t size
Definition: bytesobject.h:86
maxon::Int Int
Definition: ge_sys_math.h:64
@ NONE
Never show an error dialog.
- Note
- The data stored in memory may be written to a file using HyperFile::WriteMemory().
Functionality
Select Files and Folders
A Filename object is also useful to open dialogs to select files and folders:
The files that can be selected in a dialog can be filtered with these flags:
The type of dialog is defined with this flag:
maxon::Id callerId(
"net.mycompany.myplugin.fileselectdialog");
{
{
}
}
static maxon::Result< Bool > FileSelectMultiple(FILESELECT flags, const maxon::String &title, const maxon::Url &startUrl, const maxon::Id &settingsIdentifier, const maxon::Block< maxon::Tuple< maxon::String, maxon::String >> &filterStrings, const maxon::ValueReceiver< const maxon::Url & > &selectedUrls)
Definition: basearray.h:412
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append(ARG &&x)
Definition: basearray.h:677
Definition: apibaseid.h:253
Definition: string.h:1235
Py_UCS4 * res
Definition: unicodeobject.h:1113
maxon::Bool Bool
Definition: ge_sys_math.h:55
#define iferr_scope
Definition: resultbase.h:1374
#define iferr_return
Definition: resultbase.h:1465
Preset Browser
A Filename object may also be used to reference a file located in Cinema 4D's content browser.
{
}
PyCompilerFlags const char * filename
Definition: ast.h:15
Compare
Two Filename objects can be compared easily:
{
if (folder == desktop)
else
}
#define C4D_PATH_DESKTOP
OS desktop directory.
Definition: c4d_file.h:1923
const Filename GeGetC4DPath(Int32 whichpath)
Disc I/O
A Filename object can be stored in a BaseFile or a HyperFile using:
if (bf == nullptr)
bf->WriteFilename(filenameData);
bf->Close();
@ ANY
Show an error dialog for any error.
if (bf == nullptr)
bf->ReadFilename(&filenameData);
bf->Close();
@ READ
Open the file for reading.
if (hf == nullptr)
hf->WriteFilename(filenameData);
hf->Close();
if (hf == nullptr)
hf->ReadFilename(&filenameData);
Further Reading