About
Cinema 4D 's API provides multiple utility functions to work with files.
{
ApplicationOutput (
"Error: Didn't find a file called \"testdocument.txt\" below the desktop directory." _s);
}
{
const maxon::String errMsg =
"Error: The selected file (" _s +
src +
") doesn't exist." _s;
}
fnNewDir += "myDir" ;
fnNewDir += "mySubDir1" ;
fnNewDir += "mySubDir2" ;
{
}
InfoStop(fnNewDir,
"New directory successfully created, watch opened Explorer/Finder" _s)
iferr_return ;
{
const maxon::String errMsg =
"Error: Failed to copy file (" _s +
src +
") to " _s + dst;
}
InfoStop(fnDest,
"Source file successfully copied to new directory, watch opened Explorer/Finder" _s)
iferr_return ;
fnDestRenamed.
SetFile (
"newName.test" );
{
const maxon::String errMsg =
"Error: Failed to rename file (" _s + dest +
") to " _s + renamed;
}
InfoStop(fnDestRenamed,
"File successfully renamed, watch opened Explorer/Finder" _s)
iferr_return ;
fnDestMoved += "myDir" ;
fnDestMoved += fnDestRenamed.
GetFile ();
if (!
GeFMove (fnDestRenamed, fnDestMoved))
{
const maxon::String errMsg {
"Error: Failed to move file (" _s + renamed +
") to " _s + moved };
}
InfoStop(fnDestMoved,
"File successfully moved, watch opened Explorer/Finder" _s)
iferr_return ;
fnDelDir += "myDir" ;
{
const maxon::String errMsg =
"Error: Failed to delete created directories and files (" _s + dir +
")" _s;
}
InfoStop(fnDestMoved,
"Successfully deleted all directories/files created in this test, watch opened Explorer/Finder" _s)
iferr_return ;
File Functions
All the usual functions to work with files (copy, rename, delete,...) are available in Cinema 4D 's API:
Note If a new file needs to be created from scratch, please see BaseFile Manual or HyperFile Manual .
Warning Beware, GeFKill() deletes files permanently. The files will not be moved to system's trash can.
Note For similar functions of the MAXON API ALIASES see File Functions .
Folders/Directories
Creation
Default Paths
Note For similar functions of the MAXON API ALIASES see Application .
File Attributes
{
sAttr = "" _s;
sAttr += "RO_" _s;
else
sAttr += "RW_" _s;
sAttr += "H_" _s;
else
sAttr += "__" _s;
sAttr += "L_" _s;
else
sAttr += "__" _s;
sAttr += "r" _s;
else
sAttr += "_" _s;
sAttr += "w" _s;
else
sAttr += "_" _s;
sAttr += "x" _s;
else
sAttr += "_" _s;
sAttr += "r" _s;
else
sAttr += "_" _s;
sAttr += "w" _s;
else
sAttr += "_" _s;
sAttr += "x" _s;
else
sAttr += "_" _s;
sAttr += "r" _s;
else
sAttr += "_" _s;
sAttr += "w" _s;
else
sAttr += "_" _s;
sAttr += "x" _s;
else
sAttr += "_" _s;
}
File Execution
GeExecuteFile() : Opens the file as if the user double-clicked it. The default application for this file will open.
GeExecuteProgram() : Asynchronously executes an application.
GeOpenHTML() : Opens an URL in the user's default web browser.
Volumes/Drives
File Type Identification
GeIdentifyFile() : Identifies the type of a file.
Parameter "recognition", identification flags:
IdentifyImage() : Identifies the type of an image file.
Return value, image types:
GeGetMovieInfo() : Retrieves information from a movie file.
Note For similar function of the MAXON API ALIASES see FileFormatHandlerInterface .
Documents
BaseDocument class contains functions to load documents from files (LoadDocument() and LoadFile() ). See Disc I/O in the BaseDocument Manual for more information.
Images
BaseBitmap class contains functions to read/write images from/to files (BaseBitmap::Init() and BaseBitmap::Save() ). Images can also be read/written from/to a HyperFile (HyperFile::ReadImage() and HyperFile::WriteImage() ). See Disc I/O in the BaseBitmap Manual and BaseBitmap in HyperFile Manual for more information.
Sounds
Sound files can be loaded and saved with the respective functions (BaseSound::Load() and BaseSound::Save() ) of the BaseSound class.
Miscellaneous
ShowInFinder() : Shows the file/path in the Finder (Mac) or Explorer (Windows).
Further Reading
#define GE_FILE_ATTRIBUTE_GROUP_R
Group read file permission.
Definition: c4d_file.h:1736
void MessageDialog(const maxon::String &str)
#define GE_FILE_ATTRIBUTE_HIDDEN
File is hidden.
Definition: c4d_file.h:1731
Bool GeFCreateDirRec(const Filename &name)
const Filename GetFile(void) const
Bool GeFExist(const Filename &name, Bool isdir=false)
#define GE_FILE_ATTRIBUTE_GROUP_W
Group write file permission.
Definition: c4d_file.h:1737
maxon::UInt32 UInt32
Definition: ge_sys_math.h:61
Definition: string.h:1213
#define GE_FILE_ATTRIBUTE_PUBLIC_W
Public write file permission.
Definition: c4d_file.h:1740
Manages file and path names.
Definition: c4d_file.h:93
return OK
Definition: apibase.h:2546
#define GE_FILE_ATTRIBUTE_OWNER_R
Owner read file permission.
Definition: c4d_file.h:1733
#define C4D_PATH_DESKTOP
OS desktop directory.
Definition: c4d_file.h:1908
#define iferr_return
Definition: resultbase.h:1465
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
Bool GeFRename(const Filename &source, const Filename &dest)
Bool GeFKill(const Filename &name, Int32 flags=0)
Bool GeSearchFile(const Filename &directory, const Filename &name, Filename *found)
String GetString(void) const
#define GE_FKILL_DIRECTORY
Delete directories.
Definition: c4d_file.h:1715
const T & src
Definition: apibase.h:2539
const Filename GeGetC4DPath(Int32 whichpath)
void SetFile(const Filename &str)
const Filename GetDirectory(void) const
UInt32 GeFGetAttributes(const Filename &name)
Bool ShowInFinder(const Filename &fn, Bool open)
#define GE_FKILL_RECURSIVE
Delete the children of a directory.
Definition: c4d_file.h:1716
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:208
#define GE_FILE_ATTRIBUTE_OWNER_W
Owner write file permission.
Definition: c4d_file.h:1734
Bool GeFCopyFile(const Filename &source, const Filename &dest, Int32 flags)
#define GE_FILE_ATTRIBUTE_READONLY
File is read-only.
Definition: c4d_file.h:1730
#define GE_FILE_ATTRIBUTE_OWNER_X
Owner execute file permission.
Definition: c4d_file.h:1735
#define GE_FILE_ATTRIBUTE_PUBLIC_X
Public execute file permission.
Definition: c4d_file.h:1741
Bool GeFMove(const Filename &source, const Filename &dest)
#define GE_FILE_ATTRIBUTE_GROUP_X
Group execute file permission.
Definition: c4d_file.h:1738
#define GE_FILE_ATTRIBUTE_PUBLIC_R
Public read file permission.
Definition: c4d_file.h:1739
#define GE_FILE_ATTRIBUTE_LOCKED
File is locked (Mac only).
Definition: c4d_file.h:1732