Filename API Functions: Unterschied zwischen den Versionen

Aus expecco Wiki (Version 2.x)
Zur Navigation springen Zur Suche springen
Zeile 9: Zeile 9:


=== Construction ===
=== Construction ===
:''aString'' '''asFilename''' => Filename
::given a string, make a filename instance from it

:'''Filename''' '''homeDirectory''' => Filename
:'''Filename''' '''homeDirectory''' => Filename
::return a filename representing the user's home folder
::return a filename representing the user's home folder
Zeile 21: Zeile 18:
::return a filename representing the directory for temporary files (typically, that is determined by a shell variable named "TMPDIR" or similar).
::return a filename representing the directory for temporary files (typically, that is determined by a shell variable named "TMPDIR" or similar).


:'''aFilename''' / '''aString''' => Filename
:''aString'' '''asFilename''' => Filename
::given a string, make a filename instance from it. "/"-characters in aString will be replaced by "\" on windows.

:''aFilename'' / ''aString'' => Filename
::allows for portable construction of a path. "/"-characters in aString will be replaced by "\" on windows.
::allows for portable construction of a path. "/"-characters in aString will be replaced by "\" on windows.
::eg. "Filename homeDirectory / 'myFiles' / 'foo'" or "Filename homeDirectory / 'myFiles/foo'" might generate a filename for "/usr/fritz/myFiles/foo" on Unix and "C:\Users\anton\myFiles\foo" on windows.
::eg. "Filename homeDirectory / 'myFiles' / 'foo'" or "Filename homeDirectory / 'myFiles/foo'" might generate a filename for "/usr/fritz/myFiles/foo" on Unix and "C:\Users\anton\myFiles\foo" on windows.

Version vom 18. Januar 2022, 19:16 Uhr

This document lists most useful (and most often needed) functions. Be aware, that there are many more to be found in either the class references or via the builtin class browser.

See also "File Operations" in Expecco_API.
Reference: Filename

Back to Useful API Functions

Construction[Bearbeiten]

Filename homeDirectory => Filename
return a filename representing the user's home folder
Filename currentDirectory => Filename
return a filename representing the current directory
Filename tmpDirectory => Filename
return a filename representing the directory for temporary files (typically, that is determined by a shell variable named "TMPDIR" or similar).
aString asFilename => Filename
given a string, make a filename instance from it. "/"-characters in aString will be replaced by "\" on windows.
aFilename / aString => Filename
allows for portable construction of a path. "/"-characters in aString will be replaced by "\" on windows.
eg. "Filename homeDirectory / 'myFiles' / 'foo'" or "Filename homeDirectory / 'myFiles/foo'" might generate a filename for "/usr/fritz/myFiles/foo" on Unix and "C:\Users\anton\myFiles\foo" on windows.

Queries[Bearbeiten]

aFilename exists
aFilename.exists()   [JS]
Returns true if the file exists.
Example:
 'data.txt' asFilename exists
 => false
aFilename isReadable
aFilename isWritable
aFilename isExecutable
Returns a boolean.
Notice that ïsExecutable" has a special meaning for folders (refer to your Unix/Windows operating system manual).
Example:
 'data.txt' asFilename isReadable
 => false
aFilename fileSize
Returns the file's size (in bytes). 0 if it does not exist (or is empty).
Example:
 'data.txt' asFilename fileSize
 => 0
aFilename modificationTime
aFilename creationTime
aFilename accessTime
Returns the time of the last modification, initial creation and last access of the file.
Notice that Unix operating systems do not record a file's creationTime (in contrast to Windows). There, nil will be returned for creationTime.
Example:
 '/etc' asFilename modificationTime
 => 2018-07-27 11:37:20

 'c:\tmp\test.dat' asFilename modificationTime
 => 2010-01-27 22:37:20

Queries - Name & Path[Bearbeiten]

baseName[Bearbeiten]

Returns the filename's base name. This is the name without directory path - i.e. the file's name within its containing directory.


aFilename baseName

aFilename.baseName() [JS]

Example:

 '/etc/foo.txt' asFilename baseName
 => 'foo.txt'

 'c:\foo\bar\bla.txt.dat' asFilename baseName
 => 'bla.txt.dat'

 'foo' asFilename baseName
 => 'foo'
directory / directoryName[Bearbeiten]

Returns the filename's containing directory either as a new filename instance (directory) or as string (directoryName). This is the directory part of the name.


aFilename directory

aFilename directoryName

aFilename.directory() [JS]

aFilename.directoryName() [JS]

Example:

 '/etc/foo.txt' asFilename directoryName
 => '/etc'

 'c:\foo\bar\bla.txt.dat' asFilename directoryName
 => 'c:\foo\bar'

 'foo' asFilename directoryName
 => '.'

 'c:\foo\bar\bla.txt.dat' asFilename directory directory
 => 'c:\foo'

 '/foo/bar/bla.txt.dat' asFilename directory directory
 => '/foo'
suffix[Bearbeiten]

Returns the filename's suffix, also called its filename extension. This is the part of the name after the last "." (period).


aFilename suffix

aFilename.suffix() [JS]

Example:

 'foo.txt' asFilename suffix
 => 'txt'

 'foo.txt.dat' asFilename suffix
 => 'dat'

 'foo' asFilename suffix
 =>  <- an empty string
withoutSuffix[Bearbeiten]

Returns the filename without filename extension.
That is: it returns the name before the last "." (period).


aFilename withoutSuffix

aFilename.withoutSuffix() [JS]

Example:

 '/etc/foo.txt' asFilename withoutSuffix
 => '/etc/foo'

 'c:\foo\bar\bla.txt.dat' asFilename withoutSuffix
 => 'c:\foo\bar\bla.txt'

 'foo.exe' asFilename withoutSuffix
 => 'foo'
withSuffix:[Bearbeiten]

This returns a new filename instance with a different filename extension after the last "." (period).


aFilename withSuffix: newSuffix

aFilename.withSuffix( newSuffix ) [JS]

Example:

 '/etc/foo.txt' asFilename withSuffix:dat
 => '/etc/foo.dat'

 'c:\foo\bar\bla.txt.dat' asFilename withSuffix:'bbb'
 => 'c:\foo\bar\bla.txt.bbb'

 'foo.exe' asFilename withSuffix:'dat'
 => 'foo.dat'

 'foo' asFilename withSuffix:'dat'
 => 'foo.dat'

Directory Contents[Bearbeiten]

files[Bearbeiten]

Returns a collection of all files in a directory (folder). The returned collection will not include names of subdirectories.

aFilename files

aFilename.files() [JS]

Example:

 '/etc' asFilename files
 => #( ... )
filesMatching:[caseSensitive:][Bearbeiten]

Returns a collection of all files in a directory (folder) whose name matches given GLOB multi pattern. The returned collection will not include names of subdirectories. The pattern may consist of multiple GLOB patterns, separated by semicolon.

aFilename filesMatching: multiPattern

aFilename filesMatching: multiPattern caseSensitive: boolean

aFilename.filesMatching(multiPattern) [JS]

Example:

 '/etc' asFilename filesMatching: 'a*'
 => #( ... )

 '/etc' asFilename filesMatching: 'a*;b*;x*'
 => #( ... )

 '/tmp' asFilename filesMatching: '*.dat;*.txt'
 => #( ... )
directories[Bearbeiten]

Returns a collection of all sub directories in a directory. The returned collection will not include names of regular files.

aFilename directories

aFilename.directories() [JS]

Example:

 '/etc' asFilename directories
 => #( ... )

Streaming[Bearbeiten]

readStream / writeStream / appendingWriteStream[Bearbeiten]

Returns a stream for reading or writing to the file.
See Stream API Functions on how to use streams.

Example:

|s|
s := 'test.dat' asFilename readStream.
firstLine := s nextLine.
nextChar := s next.
nextNumber := Number readFrom:s
s close



Copyright © 2014-2024 eXept Software AG