User Tools

Site Tools


File Find

Summary

Below is an example demonstrating how you can obtain an absolute path for a file in a mapped content directory using its relative path.

API Areas of Interest

Example

File_Find.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	/*********************************************************************/
	// String : A function for finding an absolute file path of a relative one
	function findAbsContentFilePath( sRelFilePath )
	{
		// If the relative path is empty
		if( sRelFilePath.isEmpty() ){
			// We are done...
			return "";
		}
 
		// Get the content manager
		var oContentMgr = App.getContentMgr();
 
		// Declare working variable
		var sFilePath;
 
		// Initialize
		var bHasAllEnums = (App.version64 >= 0x000400090000002e);//4.9.0.46
		var nDirType = DzContentMgr.AllDirs;
 
		// Get the import manager
		var oImportMgr = App.getImportMgr();
		// If the file type is imported
		if( oImportMgr.findImporter( sRelFilePath ) ){
			// If the version does not provide all enumerated values
			if( !bHasAllEnums ){
				// Update the directory type
				nDirType = DzContentMgr.PoserDirs |
							DzContentMgr.ImportDirs |
							0x20; //DzContentMgr.CloudDB
			// Otherwise
			} else {
				// Update the directory type
				nDirType = DzContentMgr.PoserDirs |
							DzContentMgr.ImportDirs |
							DzContentMgr.CloudDB;
			}
		// If the file type is native
		} else {
			// If the version does not provide all enumerated values
			if( !bHasAllEnums ){
				// Update the directory type
				nDirType = DzContentMgr.NativeDirs |
							0x20; //DzContentMgr.CloudDB
			// Otherwise
			} else {
				// Update the directory type
				nDirType = DzContentMgr.NativeDirs |
							DzContentMgr.CloudDB;
			}
		}
 
		// Return the path
		return oContentMgr.findFile( sRelFilePath, nDirType );
	};
 
	/*********************************************************************/
	// Get the absolute path of a known native relative path
	var sFilePath = findAbsContentFilePath( "People/Genesis 3 Female/Genesis 3 Female.duf" );
 
	// Provide feedback
	print( sFilePath );
 
	// Get the absolute path of a known imported relative path
	sFilePath = findAbsContentFilePath( "Runtime/Geometries/Props/ball.obj" );
 
	// Provide feedback
	print( sFilePath );
 
// Finalize the function and invoke
})();