External File Methods

 

getFiles <wild_card_filename_string>

Returns an array of file names that match the given wild-card path name. The following example gets an array of all the .max scene files in c:\foo and then loops over the array, opening each file and printing the objects in each:

files = getFiles "c:\\foo\\*.max"

for f in files do (loadMAXFile f; print objects)

getFiles() can also be used to determine if a file exists.

For example,

the following function will return true if the specified file name exists:

fn existFile fname = (getfiles fname).count != 0

 

getDirectories <wild_card_directory_name_string>

Returns an array of directory paths that match the given wild-card directory path name.

Script:

fn getFilesRecursive root pattern =

(

dir_array = GetDirectories (root+"/*")

for d in dir_array do

join dir_array (GetDirectories (d+"/*"))

 

my_files = #()

for f in dir_array do

join my_files (getFiles (f + pattern))

my_files

)

--get all .ms files from the max installation

getFilesRecursive "c:/3dsmax5" "*.ms"

 

makeDir <directory_path_string> all:<boolean>

Creates a new directory with the given name. Returns true on success, false on failure (either because the path could not be created or because the path already existed).

new.gif If the optional all: keyword argument is set to true (default since 3ds Max 9, in 3ds Max 8 the default was false), all sub-directory levels specified in the path will be created if they do not exist.

 

deleteFile <filename_string>

Deletes the named file. Fails if the file is open in MAXScript. Returns true on success, false on failure.

 

renameFile <old_filename_string> <new_filename_string>

Renames the old file to the new file. This can also be used to move a file between directories. Fails if new file already exists or if the old file is open in MAXScript. Returns true on success, false on failure.

 

copyFile <existing_filename_string> <new_filename_string>

Copies the existing file to the new file. Fails if the new file already exists, the new file cannot be created, or the existing file is open in MAXScript. Returns true on success, false on failure.

 

getFileSize <filename_string>

Returns the size of the specified file in bytes. Returns 0 if the file could not be found.

 

getFileAttribute <filename_string> <attribute>

setFileAttribute <filename_string> <attribute> <boolean>

Get and set the attributes associated with a file. The get function returns true or false depending on the state of the specified attribute, the set function sets the state of the individual attribute specified (leaving other attributes as they were). The valid <attribute> values are:

#readOnly

#hidden

#system

#directory

#archive

#temporary

#normal

getFileModDate <filename_string>

Returns a String value containing the modification date for the specified file, for example "1/29/99 1:52:05 PM".

 

getFileCreateDate <filename_string>

Returns a String value containing the creation date for the specified file.

 

getFileVersion <filename_string>

Returns the file and product version for the specified file, or unknown if this data is not specified in the file. This data is typically specified only for executable and application extension (i.e., .dll) files.

For example:

GetFileVersion "g:\\3dsmax25\3dsmax.exe"

returns "2,5,0,0 2,5,0,0"

Examples:

for f in getFiles "3dsmax\\maps\\*.jpg" do deleteFile f

for d in getDirectories "D:\\foo\\*" do

for f in getFiles (d + "*.*") do

copyFile f ("C:\\temp\\" + getFilenameFile f + getFilenameType f)

if (getFiles "foo.max").count == 0 then print "File missing"

getMAXIniFile()

In 3ds Max 6 and higher, returns the current 3dsmax.ini file as a string. For some products that store the ini settings in the registry, this method returns undefined.

See also

Filestream Values

File Name Parsing

Standard Open and Save File Dialogs