File Functions Manual

内容表

关于

Cinema 4D 's API provides multiple utility functions to work with files.

// Small helper function demonstrating ShowInFinder(). static maxon::Result<void> InfoStop( const Filename & fn, const maxon::String & msg); static maxon::Result<void> InfoStop( const Filename & fn, const maxon::String & msg) { if (! ShowInFinder (fn, false )) return maxon::UnknownError( MAXON_SOURCE_LOCATION );
MessageDialog (msg);
return maxon::OK ; }

// A useless example to demonstrate a bunch of file functions.

// First get the desktop directory, this example will search for a testdocument.txt below the desktop. const Filename fnDesktop = GeGetC4DPath ( C4D_PATH_DESKTOP ); Filename fnSrc;

// Search for a test file. if (! GeSearchFile (fnDesktop, "testdocument.txt" , &fnSrc)) { ApplicationOutput ( "Error: Didn't find a file called \"testdocument.txt\" below the desktop directory." _s); ApplicationOutput ( " Please create one for this demo to work." _s); return maxon::OK ; }

// Check if file exists (well, in this case it always does, as GeSearchFile() returned true). if (! GeFExist (fnSrc, false )) { const maxon::String src = maxon::String (fnSrc. GetString ()); const maxon::String errMsg = "Error: The selected file (" _s + src + ") doesn't exist." _s; return maxon::UnexpectedError( MAXON_SOURCE_LOCATION , errMsg); }

// Create a few sub-directories in the directory containing the "test file". Filename fnNewDir = fnSrc. GetDirectory (); fnNewDir += "myDir" ; fnNewDir += "mySubDir1" ; fnNewDir += "mySubDir2" ; if (! GeFCreateDirRec (fnNewDir)) // Note: GeFCreateDirRec() has to be used if several sub-directories are to be created in one step. { return maxon::UnexpectedError( MAXON_SOURCE_LOCATION , "Error: Failed to create directory: " _s + maxon::String (fnNewDir. GetString ())); } InfoStop(fnNewDir, "New directory successfully created, watch opened Explorer/Finder" _s) iferr_return ; // small helper function

// Copy the file into the sub-directory. const Filename fnDest = fnNewDir + fnSrc. GetFile (); if (! GeFCopyFile (fnSrc, fnDest, 0)) { const maxon::String src = maxon::String (fnSrc. GetString ()); const maxon::String dst = maxon::String (fnDest. GetString ()); const maxon::String errMsg = "Error: Failed to copy file (" _s + src + ") to " _s + dst; return maxon::UnexpectedError( MAXON_SOURCE_LOCATION , errMsg); } InfoStop(fnDest, "Source file successfully copied to new directory, watch opened Explorer/Finder" _s) iferr_return ; // small helper function

// Rename the copy. Filename fnDestRenamed = fnDest; fnDestRenamed. SetFile ( "newName.test" ); if (! GeFRename (fnDest, fnDestRenamed)) { const maxon::String dest = maxon::String (fnDest. GetString ()); const maxon::String renamed = maxon::String (fnDestRenamed. GetString ()); const maxon::String errMsg = "Error: Failed to rename file (" _s + dest + ") to " _s + renamed; return maxon::UnexpectedError( MAXON_SOURCE_LOCATION , errMsg); } InfoStop(fnDestRenamed, "File successfully renamed, watch opened Explorer/Finder" _s) iferr_return ; // small helper function

// Move the renamed copy. Filename fnDestMoved = fnSrc. GetDirectory (); fnDestMoved += "myDir" ; fnDestMoved += fnDestRenamed. GetFile (); if (! GeFMove (fnDestRenamed, fnDestMoved)) { const maxon::String renamed { fnDestRenamed. GetString () }; const maxon::String moved { fnDestMoved. GetString () }; const maxon::String errMsg { "Error: Failed to move file (" _s + renamed + ") to " _s + moved }; return maxon::UnexpectedError( MAXON_SOURCE_LOCATION , errMsg); } InfoStop(fnDestMoved, "File successfully moved, watch opened Explorer/Finder" _s) iferr_return ; // small helper function

// Finally, remove the file and all created directories again. Filename fnDelDir = fnSrc. GetDirectory (); fnDelDir += "myDir" ; if (! GeFKill (fnDelDir, GE_FKILL_DIRECTORY | GE_FKILL_RECURSIVE )) { const maxon::String dir { fnDelDir. GetString () }; const maxon::String errMsg = "Error: Failed to delete created directories and files (" _s + dir + ")" _s; return maxon::UnexpectedError( MAXON_SOURCE_LOCATION , errMsg); } InfoStop(fnDestMoved, "Successfully deleted all directories/files created in this test, watch opened Explorer/Finder" _s) iferr_return ; // small helper function

File Functions

All the usual functions to work with files (copy, rename, delete,...) are available in Cinema 4D 's API:

注意
If a new file needs to be created from scratch, please see BaseFile Manual or HyperFile Manual .
警告
Beware, GeFKill() deletes files permanently. The files will not be moved to system's trash can.
注意
For similar functions of the MAXON API see File Functions .

Folders/Directories

Creation

Default Paths

注意
For similar functions of the MAXON API see 应用程序 .

File Attributes

// Small helper function to decode file attributes into a string. static maxon::Result<void> FileGetAttributesString( const Filename & fn, maxon::String & sAttr) { const UInt32 attr = GeFGetAttributes (fn); sAttr = "" _s;

// Note: Depending on the platform (Win/OSX) not all flags make sense. if (attr & GE_FILE_ATTRIBUTE_READONLY ) sAttr += "RO_" _s; else sAttr += "RW_" _s; if (attr & GE_FILE_ATTRIBUTE_HIDDEN ) sAttr += "H_" _s; else sAttr += "__" _s; if (attr & GE_FILE_ATTRIBUTE_LOCKED ) sAttr += "L_" _s; else sAttr += "__" _s; if (attr & GE_FILE_ATTRIBUTE_OWNER_R ) sAttr += "r" _s; else sAttr += "_" _s; if (attr & GE_FILE_ATTRIBUTE_OWNER_W ) sAttr += "w" _s; else sAttr += "_" _s; if (attr & GE_FILE_ATTRIBUTE_OWNER_X ) sAttr += "x" _s; else sAttr += "_" _s; if (attr & GE_FILE_ATTRIBUTE_GROUP_R ) sAttr += "r" _s; else sAttr += "_" _s; if (attr & GE_FILE_ATTRIBUTE_GROUP_W ) sAttr += "w" _s; else sAttr += "_" _s; if (attr & GE_FILE_ATTRIBUTE_GROUP_X ) sAttr += "x" _s; else sAttr += "_" _s; if (attr & GE_FILE_ATTRIBUTE_PUBLIC_R ) sAttr += "r" _s; else sAttr += "_" _s; if (attr & GE_FILE_ATTRIBUTE_PUBLIC_W ) sAttr += "w" _s; else sAttr += "_" _s; if (attr & GE_FILE_ATTRIBUTE_PUBLIC_X ) sAttr += "x" _s; else sAttr += "_" _s; return maxon::OK ; }

File Execution

Volumes/Drives

File Type Identification

注意
For similar function of the MAXON API see FileFormatHandlerInterface .

Documents

BaseDocument class contains functions to load documents from files ( LoadDocument() and LoadFile() ). See Disc I/O BaseDocument Manual 了解更多信息。

图像

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 BaseBitmap Manual and BaseBitmap in HyperFile Manual 了解更多信息。

Sounds

Sound files can be loaded and saved with the respective functions ( BaseSound::Load() and BaseSound::Save() ) of the BaseSound class.

杂项

延伸阅读

GE_FILE_ATTRIBUTE_GROUP_R
#define GE_FILE_ATTRIBUTE_GROUP_R
Group read file permission.
定义: c4d_file.h:1736
MessageDialog
void MessageDialog(const maxon::String &str)
GE_FILE_ATTRIBUTE_HIDDEN
#define GE_FILE_ATTRIBUTE_HIDDEN
File is hidden.
定义: c4d_file.h:1731
GeFCreateDirRec
Bool GeFCreateDirRec(const Filename &name)
Filename::GetFile
const Filename GetFile(void) const
GeFExist
Bool GeFExist(const Filename &name, Bool isdir=false)
GE_FILE_ATTRIBUTE_GROUP_W
#define GE_FILE_ATTRIBUTE_GROUP_W
Group write file permission.
定义: c4d_file.h:1737
UInt32
maxon::UInt32 UInt32
定义: ge_sys_math.h:59
maxon::String
定义: string.h:1197
GE_FILE_ATTRIBUTE_PUBLIC_W
#define GE_FILE_ATTRIBUTE_PUBLIC_W
Public write file permission.
定义: c4d_file.h:1740
Filename
Manages file and path names.
定义: c4d_file.h:93
maxon::OK
return OK
定义: apibase.h:2532
GE_FILE_ATTRIBUTE_OWNER_R
#define GE_FILE_ATTRIBUTE_OWNER_R
Owner read file permission.
定义: c4d_file.h:1733
C4D_PATH_DESKTOP
#define C4D_PATH_DESKTOP
OS desktop directory.
定义: c4d_file.h:1908
iferr_return
#define iferr_return
定义: resultbase.h:1434
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
GeFRename
Bool GeFRename(const Filename &source, const Filename &dest)
GeFKill
Bool GeFKill(const Filename &name, Int32 flags=0)
GeSearchFile
Bool GeSearchFile(const Filename &directory, const Filename &name, Filename *found)
Filename::GetString
String GetString(void) const
GE_FKILL_DIRECTORY
#define GE_FKILL_DIRECTORY
Delete directories.
定义: c4d_file.h:1715
maxon::src
const T & src
定义: apibase.h:2525
maxon::Result< void >
GeGetC4DPath
const Filename GeGetC4DPath(Int32 whichpath)
Filename::SetFile
void SetFile(const Filename &str)
Filename::GetDirectory
const Filename GetDirectory(void) const
GeFGetAttributes
UInt32 GeFGetAttributes(const Filename &name)
ShowInFinder
Bool ShowInFinder(const Filename &fn, Bool open)
GE_FKILL_RECURSIVE
#define GE_FKILL_RECURSIVE
Delete the children of a directory.
定义: c4d_file.h:1716
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
GE_FILE_ATTRIBUTE_OWNER_W
#define GE_FILE_ATTRIBUTE_OWNER_W
Owner write file permission.
定义: c4d_file.h:1734
GeFCopyFile
Bool GeFCopyFile(const Filename &source, const Filename &dest, Int32 flags)
GE_FILE_ATTRIBUTE_READONLY
#define GE_FILE_ATTRIBUTE_READONLY
File is read-only.
定义: c4d_file.h:1730
GE_FILE_ATTRIBUTE_OWNER_X
#define GE_FILE_ATTRIBUTE_OWNER_X
Owner execute file permission.
定义: c4d_file.h:1735
GE_FILE_ATTRIBUTE_PUBLIC_X
#define GE_FILE_ATTRIBUTE_PUBLIC_X
Public execute file permission.
定义: c4d_file.h:1741
GeFMove
Bool GeFMove(const Filename &source, const Filename &dest)
GE_FILE_ATTRIBUTE_GROUP_X
#define GE_FILE_ATTRIBUTE_GROUP_X
Group execute file permission.
定义: c4d_file.h:1738
GE_FILE_ATTRIBUTE_PUBLIC_R
#define GE_FILE_ATTRIBUTE_PUBLIC_R
Public read file permission.
定义: c4d_file.h:1739
GE_FILE_ATTRIBUTE_LOCKED
#define GE_FILE_ATTRIBUTE_LOCKED
File is locked (Mac only).
定义: c4d_file.h:1732

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1