Volumes with different file name lengths
The formatFilename: method can be used to shorten its filename argument to fit the volumes' maximumFilenameLength restrictions by dropping vowels and truncating, if necessary. This method assumes that a maximumFilenameLength of 12 indicates that file names should consist of eight characters, optionally followed by a period and a three character extension. The formatFilename: method does not detect or suppress characters that are not valid.
File names should be composed of the POSIX.1 portable file name characters, which are listed in
"Portable file names".
Note:
If volume information cannot be obtained due to an OS error, caseSensitive, preservesCase and maximumFilenameLength will be set to conservative values (true, false, and 12 respectively) and formatFilename: will operate on these values. This behavior is provided for cases where the volume information cannot be obtained due to an OS error, such as when no disk is present in drive.
The following example forces a file name to conform to the file name length and case of the volume specified by path. For further information on the
systemErrorDialog: method, see
Suppressing system error dialogs.
"Modify the file name for the file about to be saved to path,
ignoring all errors, including drive not ready."
| filename path state volumeInfo newFilename |
filename := 'aVeryLongFilenameWhichWontFitOnSomeSystems.Text'.
path := 'a:\workdir'.
"Obtain volume information"
(volumeInfo := CfsVolumeInfo new) volumeInfo: path.
"Force the filename to fit"
newFilename := volumeInfo formatFilename: filename.
"Answer the full path"
^path last = CfsDirectoryDescriptor pathSeparator
ifTrue: [path, newFilename]
ifFalse: [path, CfsDirectoryDescriptor pathSeparatorString, newFilename]
Last modified date: 01/29/2015