Project

General

Profile

Actions

Scripting Files Folders » History » Revision 7

« Previous | Revision 7/13 (diff) | Next »
Per Amundsen, 02/26/2017 02:20 PM


File/Folder Handling

$crc

Added in 1.9.0

$crc(text|&binvar|filename,[N])

Returns the CRC checksum of the specified item.

Parameters

Parameter Description
text|&binvar|filename Value to calculate CRC checksum from.
N 0 = plain text, 1 = &binvar, 2 = filename (content of the file), 2 is default.

$exists

Added in 1.9.0

$exists(file|dir)

Returns $true if a file or dir exists otherwise $false.

See also $isfile $isdir.

Parameters

Parameter Description
file|dir File or directory.

Example

; Check if file exists
if ($exists(c:\windows\notepad.exe) file exists

; Check if directory exists
if ($exists(c:\windows) directory exists

$file

Added in 1.8.10

$file(filename|foldername|name)

Returns information about the specified file or folder.

Default returns file size.

Same as $lof.

Parameters

Parameter Description
filename|foldername|name Filename or folder or open file in $fopen to retrieve information from.

Properties

Property Description
.size File size in bytes. (returns 0 for folders)
.ctime Creation time. (unix timestamp)
.mtime Last modification time. (unix timestamp)
.atime Last access time. (unix timestamp)
.shortfn Short file name.
.longfn Full file name.
.attr File attributes.
.sig Returns "ok" if digital signed, else "none".
.version Returns the file version, if any.
.path The path directory.
.name The filename without the file extension.
.ext The file extension.
.pid Returns the first process id started by this file. (AdiIRC Only)

Example

; Show AdiIRC.exe filesize
//echo -ag $file($adiircexe).size

; Show explorer.exe digital signature
//echo -ag $file(c:\windows\explorer.exe).sig

$finddir

Added in 1.9.0

$finddir(dir,wildcard,N,[depth],[@window|command])

Searches the specified directory and its sub directories for the Nth directory name matching the wildcard specification and returns the full path and directory if it is found.

If /halt is used in the [command], the search is halted instead of the entire script.

Parameters

Parameter Description
dir The directory to search.
wildcard Wildcard to search for.
N If N = 0, number of directories, otherwise the Nth directory.
[depth] Maximum folder depth. (optional)
[@window|command] Custom window name to fill with the result or a command to run on each result. (optional)

Properties

Property Description
.shortfn Return the path in a shortfn format.

Example

; Print number of sub directories found in $adiircdir.
//echo -ag $finddir($adiircdir,*.*,0)

; Print the 1st directory found.
//echo -ag $finddir($adiircdir,*.*,1)

; Print all sub directories in $adiircdir, when using the command parameter, $1- will hold the path.
//noop $finddir($adiircdir,*.*,0,echo -ag $1-)

$findfile

Added in 1.9.0

$findfile(dir,wildcard,N,[depth],[@window|command])

Searches the specified directory and its subdirectories for the Nth filename matching the wildcard file specification and returns the full path and filename if it is found.

If /halt is used in the [command], the search is halted instead of the entire script.

Parameters

Parameter Description
dir The directory to search.
wildcard Wildcard to search for.
N If N = 0, number of files, otherwise the Nth filename.
[depth] Maximum folder depth. (optional)
[@window|command] Custom window name to fill with the result or a command to run on each result. (optional)

Properties

Property Description
.shortfn Return the path in a shortfn format.

Example

; Print number of filenames found in $adiircdir.
//echo -ag $findfile($adiircdir,*.*,0)

; Print the 1st filename found.
//echo -ag $findfile($adiircdir,*.*,1)

; Print all filenames in $adiircdir, when using the command parameter, $1- will hold the path.
//noop $findfile($adiircdir,*.*,0,echo -ag $1-)

$getdir

Added in 1.9.0

$getdir

Returns the DCC download directory specified in Options -> DCC.


$getdir(filespec)

Returns the DCC download directory matching the filespec, otherwise the directory specified in Options -> DCC.

Parameters

Parameter Description
filespec The filespec.

Example

; Get the directory for .mp3 files.
//echo -ag $getdir(*.mp3)

$isdir

Added in 1.8.10

$isdir(dirfile)

Returns $true if the specified directory exists, otherwise $false.

Parameters

Parameter Description
dirfile Directory to check.

Example

; Check if 'windows' exists.
//if ($isdir(C:\Windows)) echo -ag directory exists

$isfile

Added in 1.8.10

$isfile(file)

Returns $true if the specified file exists, otherwise $false.

Parameters

Parameter Description
file File to check.

Example

; Check if notepad.exe exists.
//if ($isfile(C:\Windows\notepad.exe)) echo -ag file exists

$lines

Added in 1.9.0

$lines(filename)

Returns the total number of lines in the specified text file.

Parameters

Parameter Description
filename Filename to read from.

Example

;Open a file for writing
/fopen file file.txt

;Write a line to the file
/fwrite file Hello World

;Close the file
/fclose file

;Print the number of lines in file.txt
//echo -ag $lines(file.txt)
<pre>

$logdir

Added in 1.8.10

$logdir

Returns the Logs directory set in Options -> Logging -> Log folder.

$longfn

Added in 1.9.0

$longfn(filename)

Returns the long version of a short filename.

Parameters

Parameter Description
filename The filename.

Example

alias Example {
  ; Get the shortfn of AdiIRC.exe
  var %short $shortfn($adiircexe)

  ; Print the long filename
  echo -ag $longfn(%short) vs %short
}

$shortfn

{{include($shortfn}}

$mircexe

Added in 1.9.0

$mircexe

Returns the full path and filename of the AdiIRC executable file.

Same as $adiircexe.

Can be used inside text without being surrounded by white spaces.

Example

//echo -ag the adiirc exe file is $mircexe.. notice how $mircexeisreplacedhere

$adiircexe

Added in 1.9.0

$adiircexe

Returns the full path and filename of the AdiIRC executable file.

In combination with $~ this can be used to test which client is running the script. You cannot assume the client name based on the filename.exe, but instead testing whether $adiircexe exists as a built-in identifier. The $~ prefix allows the test to evade the presence of a custom alias of that name, and it also does not trigger the optional identifier warning.

//if (!$~adiircexe) echo -a this script is not running in AdiIRC

Same as $mircexe.

Can be used inside text without being surrounded by white spaces.

Example

//echo -ag the adiirc exe file is $adiircexe.. notice how $adiircexeisreplacedhere

$mircini

Added in 1.9.0

$mircini

Returns the full path and filename of the AdiIRC settings file (config.ini).

Same as $adiircini.

Can be used inside text without being surrounded by white spaces.

Example

//echo -ag the adiirc ini file is $mircini .. notice how $mirciniisreplacedhere

$adiircini

Added in 1.9.0

$adiircini

Returns the full path and filename of the AdiIRC settings file (config.ini).

Same as $mircini.

Can be used inside text without being surrounded by white spaces.

Example

//echo -ag the adiirc ini file is $adiircini.. notice how $adiirciniisreplacedhere

$mircdir

Added in 1.9.0

$mircdir

Returns the directory where AdiIRC stores its settings, themes, scripts and so on.

Same as $adiircdir.

Can be used inside text without being surrounded by white spaces.

Example

; Print the scripts folder, no space after $mircdir is needed.
//echo -ag $mircdir\Scripts

$adiircdir

Added in 1.9.0

$adiircdir

Returns the directory where AdiIRC stores its settings, themes, scripts and so on.

Can be used inside text without being surrounded by white spaces.

Same as $mircdir.

Example

; Print the scripts folder, no space after $adiircdir is needed.
//echo -ag $adiircdir\Scripts

$scriptdir

Added in 1.9.0

$scriptdir

Returns the directory of the currently executing script.

Can be used inside text without being surrounded by white spaces..

Example

; Print the script directory.
//echo -ag current scriptdir is $scriptdir

; Print the script directory inside text.
//echo -ag $scriptdir\somefile.ini

$mkfn

Added in 1.9.0

$mkfn(filename)

Replaces invalid filename characters with underscore.

Parameters

Parameter Description
filename The filename to format.

Example

; Format the filename 'tes\t.txt' to 'tes_t.txt'
//echo -ag $mkfn(tes\t.txt)

$mklogfn

Added in 1.9.0

$mklogfn(filename)

Returns the filename formatted according to options set in Options -> Logging.

Parameters

Parameter Description
filename The filename to format.

$mknickfn

Added in 1.9.0

$mknickfn(nickname)

Formats a nick for use as a valid filename.

Removes certain characters from the nick.

Parameters

Parameter Description
nickname The nickname to format.

Example

; Format the nickname 'tes\t' to 'test'
//echo -ag $mknickfn(tes\t)

$msfile

Added in 1.9.0

$msfile(dir,[title],[oktext])

Displays the multiple select file dialog and returns the number of selected files.

Parameters

Parameter Description
dir Starting folder in the file dialog.
[title] Dialog title text. (optional)
[oktext] TODO (optional)

Example

; Select some files and print the number of selected files.
//echo -ag Number of selected files is $msfile($adiircdir, Select Files)

$msfile(N)

Returns the Nth file from the last $msfile selection.

Parameters

Parameter Description
N If N = 0, number of selected files, otherwise the Nth selected file.

Example

; Select some files.
//noop $msfile($adiircdir, Select Files)

; Print the first selected file.
//echo -ag First selected file was $msfile(1)

$nofile

Added in 1.9.0

$nofile(filename)

Returns the path in filename without the actual filename.

Parameters

Parameter Description
filename The filename to extract the path from.

Example

; Print the path 'c:\windows\notepad.exe' without the filename.
//echo -ag $nofile(c:\windows\notepad.exe)

$nopath

Added in 1.9.0

$nopath(filename)

Returns filename without a path if it has one.

Parameters

Parameter Description
filename The filename/path to get the filename from.

Example

; Print the filename for the path 'c:\windows\notepad.exe'.
//echo -ag $nopath(c:\windows\notepad.exe)

$read

Added in 1.9.0

$read(filename, [ntswrp], [matchtext], [N])

Returns a single line of text from a file.

See also $readn.

Parameters

Parameter Description
filename Filename to read.
[ntswrp] (optional)
[matchtext] Matchtext to search. (optional)
[N] The Nth line.

Options

Option Description
n Don't evaluate any identifiers in the line.
t Treat the first line as a plain text, even if it's a number.
s Search for matchtext.
w Search for case-insensitive matchtext as a wildmatch.
W Search for case-sensitive matchtext as a wildmatch. (AdiIRC only)
r Search for matchtext as a regular expression.
p Treat command | separators as such instead of as plain text.

Example

; Prints a random line from the file 'file.txt'.
//echo $read(file.txt)

; Prints line '10' from the file 'file,txt.
//echo $read(file.txt, 10)

; Searches file 'file,txt for a line beginning with the text 'Hello World' and prints the text following the match value.
//echo $read(file.txt, s, Hello World)

; Searches file 'file.txt' for a line matching the wildmatch '*Hello World*' and prints it.
//echo $read(file.txt, w, *Hello World*)

$readn

Added in 1.9.0

$readn

Returns the line number that was matched in a previous call to $read. If no match was found, $readn is set to zero.

Example

; Read a random line from the file 'file.txt'.
//noop $read(file.txt)

; Print the line number from the last $read.
//echo -ag Line number from the last read was: $readn

$sdir

Added in 1.9.0

$sdir(dir,[title],[oktext])

Displays the select folder dialog and returns the selected folder.

Parameters

Parameter Description
dir Starting folder in the folder dialog.
[title] Dialog title text. (optional)
[oktext] TODO (optional)

Example

; Open the folder dialog.
//echo -ag $sdir(c:\windows,Select Folder)

$sfile

Added in 1.9.0

$sfile(file,[title],[oktext])

Displays the select file dialog and returns the selected file.

Parameters

Parameter Description
file Start filename filter in the file dialog.
[title] Dialog title text. (optional)
[oktext] TODO (optional)

Example

; Open the file dialog.
//echo -ag $sfile(*.*,Select File)

$sysdir

Added in 1.9.7

$sysdir(item)

Returns the system folder for the specified item.

Parameters

Parameter Description
item The item to retrieve: profile, desktop, documents, downloads, music, pictures and videos.

Example

; Retrieve the documents folder
//echo -ag Documents folder is $sysdir(documents)

/write

Added in 1.9.0

/write [-cidnaiNmN l<line> s<text> w<wildcard> r</regex/>] <filename> [text]

Writes lines to a text file.

Switches

Switch Description
-c Clears the entire file before writing to it.
-i Inserts the text at a given line instead of replacing it.
-d Deletes the given or last line.
-n Prevent adding $crlf at the end of the text.
-a Appends the text to an existing line.
-lN Line number for the line to write/modify/delete.
-sN Operates on a line that matches the scanned <text>.
-wN Operates on a line that matches the scanned <wildcard> pattern.
-r same as -w - but uses a regular expression match.
-mN changes how $crlf are written to the end of a file, where N = 0 is the default behavior, N = 1 adds $crlf to end of file if it is not already there before writing a line, and N = 2 never adds $crlf to end of file before writing a line.

Parameters

Parameter Description
<line> The line number to find.
<text> The text to scan.
<wildcard> Wildcard pattern to match.
</regex/> Regular expression pattern to match.
<filename> The file name to manipulate.
[text] The text to be written to the file.

Example

alias example {
  ; Create a file and add a few lines of text to it.
  /write Example.txt this is a cool line
  /write Example.txt hello there!
  /write Example.txt text files are cool

  ; Locate the line that starts with "hello" and insert the following text before it.
  /write -is"Hello" Example.txt This will become line 2!

  ; Delete line 1.
  /write -dl1 Example.txt
}

Updated by Per Amundsen over 7 years ago · 7 revisions

Also available in: PDF HTML TXT