Skip to content

Instantly share code, notes, and snippets.

@MarkTiedemann
Created April 26, 2022 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkTiedemann/c09ff0c6854af8f75edd0364d467c435 to your computer and use it in GitHub Desktop.
Save MarkTiedemann/c09ff0c6854af8f75edd0364d467c435 to your computer and use it in GitHub Desktop.
/// <reference no-default-lib="true"/>
interface ActiveXObject {
new (s: "Scripting.FileSystemObject"): FileSystemObject;
}
declare var ActiveXObject: ActiveXObject;
/**
* Provides access to a computer's file system.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/filesystemobject-object
*/
interface FileSystemObject {
/**
* Returns a `Folder` object corresponding to the folder in a specified path.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/getfolder-method
*/
GetFolder(
/** The folderspec is the path (absolute or relative) to a specific folder. */
folderspec: string
): Folder;
/**
* Creates a specified file name and returns a `TextStream` object that can be used to read from or write to the file.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/createtextfile-method
*/
CreateTextFile(
/** String expression that identifies the file to create. */
filename: string,
/** Boolean value that indicates if an existing file can be overwritten. The value is `true` if the file can be overwritten; `false` if it can't be overwritten. If omitted, existing files can be overwritten. */
overwrite?: boolean,
/** Boolean value that indicates whether the file is created as a Unicode or ASCII file. The value is `true` if the file is created as a Unicode file; `false` if it's created as an ASCII file. If omitted, an ASCII file is assumed. */
unicode?: boolean
): TextStream;
}
/**
* Facilitates sequential access to file.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/textstream-object
*/
interface TextStream {
/**
* Closes an open `TextStream` file.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/close-method-textstream-object
*/
Close(): void;
/**
* Reads an entire `TextStream` file and returns the resulting `string`.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/readall-method
*/
ReadAll(): string;
/**
* Writes a specified string and newline character to a `TextStream` file.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/writeline-method
*/
WriteLine(
/** The text you want to write to the file. If omitted, a newline character is written to the file. */
string?: string
): void;
}
/**
* Provides access to all the properties of a folder.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/folder-object
*/
interface Folder {
/**
* Returns a collection of all the files in a specified folder.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/files-property
*/
Files: Collection<File>;
}
/**
* Provides access to all the properties of a file.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/file-object
*/
interface File {
/**
* Sets or returns the name of a specified file or folder.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/name-property-filesystemobject-object
*/
Name: string;
/**
* Opens a specified file and returns a `TextStream` object that can be used to read from, write to, or append to the file.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/openastextstream-method
*/
OpenAsTextStream(
/** Indicates input/output mode. Can be one of three constants: ForReading (1), ForWriting (2), or ForAppending (8). If omitted, the file is opened ForReading. */
iomode?: 1 | 2 | 8,
/** One of three Tristate values used to indicate the format of the opened file: SystemDefault (-2), Unicode (-1) or ASCII (0). If omitted, the file is opened as ASCII. */
format?: -2 | -1 | 0
): TextStream;
}
/**
* A Collection object is an ordered set of items that can be referred to as a unit.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/collection-object
*/
interface Collection<T> {
/**
* Returns an integer containing the number of objects in a collection.
*
* @see https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/count-property-visual-basic-for-applications
*/
Count: number;
}
/** Allows enumerating a collection. */
interface Enumerator<T> {
new<T> (c: Collection<T>): Enumerator<T>;
/** Returns `true` if the current item is the last one in the collection, or the collection is empty, or the current item is `undefined`. */
atEnd(): boolean;
/** Returns the current item in the collection. */
item(): T | undefined;
/** Moves the current item to the next item in the collection. If the enumerator is at the end of the collection or the collection is empty, the current item is set to `undefined`. */
moveNext(): void;
}
declare var Enumerator: Enumerator<any>;
interface WScript {
/**
* Outputs text to the command console window followed by a newline.
*/
Echo(s: string): void;
}
declare var WScript: WScript;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment