MBMLFileFunctions Class Reference
| Inherits from | NSObject |
|---|---|
| Declared in | MBMLFileFunctions.h |
Overview
This class implements MBML functions for file management.
These functions are exposed to the Mockingbird environment via
<Function ... /> declarations in the MBDataEnvironmentModule.xml
file.
For more information on MBML functions, see the MBMLFunction class.
Working with file paths
+ lastPathComponent:
Returns the lastPathComponent of a string containing a filesystem path.
+ (id)lastPathComponent:(NSString *)pathParameters
path |
The filesystem path. |
|---|
Return Value
The lastPathComponent of path.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding a filesystem path.
Expression usage
^lastPathComponent(~/Library/Preferences/com.apple.Safari.plist)
The expression above would return the string “com.apple.Safari.plist”
Declared In
MBMLFileFunctions.h
+ stripLastPathComponent:
Removes the lastPathComponent from a filesystem path and returns the
resulting string.
+ (id)stripLastPathComponent:(NSString *)pathParameters
path |
The filesystem path. |
|---|
Return Value
The result of removing the lastPathComponent from path.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding a filesystem path.
Expression usage
^stripLastPathComponent(~/Library/Preferences/com.apple.Safari.plist)
The expression above would return the string “~/Library/Preferences”
Declared In
MBMLFileFunctions.h
+ pathExtension:
Returns the pathExtension of a string containing a filesystem path.
+ (id)pathExtension:(NSString *)pathParameters
path |
The filesystem path. |
|---|
Return Value
The pathExtension of path.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding a filesystem path.
Expression usage
^pathExtension(~/Library/Preferences/com.apple.Safari.plist)
The expression above would return the string “plist”
Declared In
MBMLFileFunctions.h
+ stripPathExtension:
Removes the pathExtension from a filesystem path and returns the
resulting string.
+ (id)stripPathExtension:(NSString *)pathParameters
path |
The filesystem path. |
|---|
Return Value
The result of removing the pathExtension from path.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding a filesystem path.
Expression usage
^stripPathExtension(~/Library/Preferences/com.apple.Safari.plist)
The expression above would return the string
“~/Library/Preferences/com.apple.Safari”
Declared In
MBMLFileFunctions.h
+ pathComponents:
Splits a filesystem path into individual path components and returns the result in an array.
+ (id)pathComponents:(NSString *)pathParameters
path |
The filesystem path. |
|---|
Return Value
An NSArray containing the path components of path.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding a filesystem path.
Expression usage
^pathComponents(~/Library/Preferences/com.apple.Safari.plist)
The expression returns an array of strings containing: [“~”, “Library”,
“Preferences”, “com.apple.Safari.plist” ].
Declared In
MBMLFileFunctions.h
Getting paths for common directories
+ directoryForHome
Returns the filesystem path of the NSHomeDirectory. On iOS, this is the
filesystem path of the application’s home.
+ (id)directoryForHomeReturn Value
The filesystem path of the directory.
Discussion
This Mockingbird function accepts no parameters.
Expression usage
^directoryForHome()
The expression above returns the filesystem path of the NSHomeDirectory.
Declared In
MBMLFileFunctions.h
+ directoryForTempFiles
Returns the filesystem path of the NSTemporaryDirectory.
+ (id)directoryForTempFilesReturn Value
The filesystem path of the directory.
Discussion
This Mockingbird function accepts no parameters.
Expression usage
^directoryForTempFiles()
The expression above returns the filesystem path of the NSTemporaryDirectory.
Declared In
MBMLFileFunctions.h
+ directoryForCaches
Returns the filesystem path of the NSCachesDirectory.
+ (id)directoryForCachesReturn Value
The filesystem path of the directory.
Discussion
This Mockingbird function accepts no parameters.
Expression usage
^directoryForCaches()
The expression above returns the filesystem path of the NSCachesDirectory.
Declared In
MBMLFileFunctions.h
+ directoryForDocuments
Returns the filesystem path of the NSDocumentDirectory.
+ (id)directoryForDocumentsReturn Value
The filesystem path of the directory.
Discussion
This Mockingbird function accepts no parameters.
Expression usage
^directoryForDocuments()
The expression above returns the filesystem path of the NSDocumentDirectory.
Declared In
MBMLFileFunctions.h
+ directoryForDownloads
Returns the filesystem path of the NSDownloadsDirectory.
+ (id)directoryForDownloadsReturn Value
The filesystem path of the directory.
Discussion
This Mockingbird function accepts no parameters.
Expression usage
^directoryForDownloads()
The expression above returns the filesystem path of the NSDownloadsDirectory.
Declared In
MBMLFileFunctions.h
+ directoryForApplicationSupport
Returns the filesystem path of the NSApplicationSupportDirectory.
+ (id)directoryForApplicationSupportReturn Value
The filesystem path of the directory.
Discussion
This Mockingbird function accepts no parameters.
Expression usage
^directoryForApplicationSupport()
The expression above returns the filesystem path of the
NSApplicationSupportDirectory.
Declared In
MBMLFileFunctions.h
+ directoryForMovies
Returns the filesystem path of the NSMoviesDirectory.
+ (id)directoryForMoviesReturn Value
The filesystem path of the directory.
Discussion
This Mockingbird function accepts no parameters.
Expression usage
^directoryForMovies()
The expression above returns the filesystem path of the NSMoviesDirectory.
Declared In
MBMLFileFunctions.h
+ directoryForMusic
Returns the filesystem path of the NSMusicDirectory.
+ (id)directoryForMusicReturn Value
The filesystem path of the directory.
Discussion
This Mockingbird function accepts no parameters.
Expression usage
^directoryForMusic()
The expression above returns the filesystem path of the NSMusicDirectory.
Declared In
MBMLFileFunctions.h
+ directoryForPictures
Returns the filesystem path of the NSPicturesDirectory.
+ (id)directoryForPicturesReturn Value
The filesystem path of the directory.
Discussion
This Mockingbird function accepts no parameters.
Expression usage
^directoryForPictures()
The expression above returns the filesystem path of the NSPicturesDirectory.
Declared In
MBMLFileFunctions.h
+ directoryForPublicFiles
Returns the filesystem path of the NSSharedPublicDirectory.
+ (id)directoryForPublicFilesReturn Value
The filesystem path of the directory.
Discussion
This Mockingbird function accepts no parameters.
Expression usage
^directoryForPublicFiles()
The expression above returns the filesystem path of the
NSSharedPublicDirectory.
Declared In
MBMLFileFunctions.h
Listing directory contents
+ listDirectory:
Lists the filenames within a given directory.
+ (id)listDirectory:(NSString *)dirParameters
dir |
The filesystem path of the directory. |
|---|
Return Value
An NSArray containing the names of the files contained within
dir.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding the filesystem path of the directory whose contents are sought.
Expression usage
^listDirectory(^directoryForHome())
The expression above returns an array containing the names of the files
within NSHomeDirectory.
Declared In
MBMLFileFunctions.h
Getting file information
+ fileExists:
Tests whether an item exists at the specified filesystem path.
+ (id)fileExists:(NSString *)filePathParameters
filePath |
The filesystem path to test. |
|---|
Return Value
@YES if the file exists at filePath; @NO otherwise.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding the filesystem path.
Expression usage
^fileExists(~/Downloads/MBToolbox.zip)
If a file exists at the path ~/Downloads/MBToolbox.zip, this expression will
return @YES. Otherwise, @NO is returned.
Declared In
MBMLFileFunctions.h
+ fileIsReadable:
Tests whether a readable item exists at the specified filesystem path.
+ (id)fileIsReadable:(NSString *)filePathParameters
filePath |
The filesystem path to test. |
|---|
Return Value
@YES if a readable file exists at filePath; @NO otherwise.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding the filesystem path.
Expression usage
^fileIsReadable(/etc/passwd)
If a readable file exists at the path /etc/passwd, this expression will
return @YES. Otherwise, @NO is returned.
Declared In
MBMLFileFunctions.h
+ fileIsWritable:
Tests whether a writable item exists at the specified filesystem path.
+ (id)fileIsWritable:(NSString *)filePathParameters
filePath |
The filesystem path to test. |
|---|
Return Value
@YES if a writable file exists at filePath; @NO otherwise.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding the filesystem path.
Expression usage
^fileIsWritable(/usr/bin/login)
If a writable file exists at the path /usr/bin/login, this expression will
return @YES. Otherwise, @NO is returned.
Declared In
MBMLFileFunctions.h
+ fileIsDeletable:
Tests whether a deletable item exists at the specified filesystem path.
+ (id)fileIsDeletable:(NSString *)filePathParameters
filePath |
The filesystem path to test. |
|---|
Return Value
@YES if a deletable file exists at filePath; @NO otherwise.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding the filesystem path.
Expression usage
^fileIsDeletable(/tmp)
If a deletable file exists at the path /tmp, this expression will
return @YES. Otherwise, @NO is returned.
Declared In
MBMLFileFunctions.h
+ isDirectoryAtPath:
Tests whether a directory exists at a given filesystem path.
+ (id)isDirectoryAtPath:(NSString *)filePathParameters
filePath |
The filesystem path to test. |
|---|
Return Value
@YES if a directory exists at filePath; @NO otherwise.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding the filesystem path.
Expression usage
^isDirectoryAtPath(~/Caches/com.gilt.ios)
If a directory file exists at the path ~/Caches/com.gilt.ios, this expression
will return @YES. Otherwise, @NO is returned.
Declared In
MBMLFileFunctions.h
+ sizeOfFile:
Returns the size of the file at the given filesystem path.
+ (id)sizeOfFile:(NSString *)filePathParameters
filePath |
The filesystem path. |
|---|
Return Value
An NSNumber containing the size of the file at filePath.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding the filesystem path.
Expression usage
The expression:
^sizeOfFile(~/Caches/com.gilt.ios/Images/superhero.jpg)
returns the size of the file at ~/Caches/com.gilt.ios/Images/superhero.jpg
in an NSNumber containing an unsigned long long value.
Declared In
MBMLFileFunctions.h
Getting file content
+ fileData:
Returns an NSData instance with the content of the file at the specified
filesystem path.
+ (id)fileData:(NSString *)filePathParameters
filePath |
The filesystem path. |
|---|
Return Value
An NSData instance containing the content of the file at
filePath.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding the filesystem path.
Expression usage
The expression:
^fileData(~/Caches/com.gilt.ios/Images/superhero.jpg)
returns the content of ~/Caches/com.gilt.ios/Images/superhero.jpg as an
NSData instance.
If the file doesn’t exist or couldn’t be read, nil will be returned.
Declared In
MBMLFileFunctions.h
+ fileContents:
Returns a UTF-8 encoded NSString instance with the content of the file at
the specified filesystem path.
+ (id)fileContents:(NSString *)filePathParameters
filePath |
The filesystem path. |
|---|
Return Value
An NSString instance containing the content of the file at
filePath.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding the filesystem path.
Expression usage
The expression:
^fileContents(~/Documents/README.txt)
returns the content of ~/Documents/README.txt as an NSString instance.
If the file doesn’t exist or couldn’t be read, nil will be returned.
Declared In
MBMLFileFunctions.h
Removing files
+ deleteFile:
Attempts to delete the item at the specified filesystem path.
+ (id)deleteFile:(NSString *)filePathParameters
filePath |
The filesystem path. |
|---|
Return Value
@YES if filePath was successfully deleted; @NO otherwise.
Discussion
This Mockingbird function accepts a single parameter: a string expression yielding the filesystem path.
Expression usage
The expression:
^deleteFile(/tmp/download-in-progress)
attempts to delete the file at /tmp/download-in-progress. If successful,
@YES is returned; otherwise, @NO is returned.
Declared In
MBMLFileFunctions.h