Cinema 4D's API provides multiple utility functions to work with files.
Filename fnSrc;
{
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;
}
Filename fnNewDir = fnSrc.GetDirectory();
fnNewDir += "myDir";
fnNewDir += "mySubDir1";
fnNewDir += "mySubDir2";
{
}
InfoStop(fnNewDir,
"New directory successfully created, watch opened Explorer/Finder"_s)
iferr_return;
const Filename fnDest = fnNewDir + fnSrc.GetFile();
{
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;
Filename fnDestRenamed = fnDest;
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;
Filename fnDestMoved = fnSrc.GetDirectory();
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;
Filename fnDelDir = fnSrc.GetDirectory();
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;
PyObject * src
Definition: abstract.h:305
#define C4D_PATH_DESKTOP
OS desktop directory.
Definition: c4d_file.h:1921
#define GE_FKILL_RECURSIVE
Delete the children of a directory.
Definition: c4d_file.h:1729
#define GE_FKILL_DIRECTORY
Delete directories.
Definition: c4d_file.h:1728
#define ApplicationOutput(formatString,...)
Definition: debugdiagnostics.h:204
const Filename GeGetC4DPath(Int32 whichpath)
Bool GeFCopyFile(const Filename &source, const Filename &dest, Int32 flags)
Bool GeFExist(const Filename &name, Bool isdir=false)
Bool GeFRename(const Filename &source, const Filename &dest)
Bool GeFCreateDirRec(const Filename &name)
Bool GeSearchFile(const Filename &directory, const Filename &name, Filename *found)
Bool GeFMove(const Filename &source, const Filename &dest)
Bool GeFKill(const Filename &name, Int32 flags=0)
#define iferr_return
Definition: resultbase.h:1531
All the usual functions to work with files (copy, rename, delete,...) are available in Cinema 4D's API:
{
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;
}
#define GE_FILE_ATTRIBUTE_GROUP_R
Group read file permission.
Definition: c4d_file.h:1749
#define GE_FILE_ATTRIBUTE_READONLY
File is read-only.
Definition: c4d_file.h:1743
#define GE_FILE_ATTRIBUTE_OWNER_W
Owner write file permission.
Definition: c4d_file.h:1747
#define GE_FILE_ATTRIBUTE_GROUP_X
Group execute file permission.
Definition: c4d_file.h:1751
#define GE_FILE_ATTRIBUTE_GROUP_W
Group write file permission.
Definition: c4d_file.h:1750
#define GE_FILE_ATTRIBUTE_PUBLIC_X
Public execute file permission.
Definition: c4d_file.h:1754
#define GE_FILE_ATTRIBUTE_PUBLIC_R
Public read file permission.
Definition: c4d_file.h:1752
#define GE_FILE_ATTRIBUTE_OWNER_X
Owner execute file permission.
Definition: c4d_file.h:1748
#define GE_FILE_ATTRIBUTE_HIDDEN
File is hidden.
Definition: c4d_file.h:1744
#define GE_FILE_ATTRIBUTE_LOCKED
File is locked (Mac only).
Definition: c4d_file.h:1745
#define GE_FILE_ATTRIBUTE_PUBLIC_W
Public write file permission.
Definition: c4d_file.h:1753
#define GE_FILE_ATTRIBUTE_OWNER_R
Owner read file permission.
Definition: c4d_file.h:1746
UInt32 GeFGetAttributes(const Filename &name)
maxon::UInt32 UInt32
Definition: ge_sys_math.h:52
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.
Sound files can be loaded and saved with the respective functions (BaseSound::Load() and BaseSound::Save()) of the BaseSound class.