diff --git a/ts-activex/microsoft-scripting-runtime-tests.ts b/ts-activex/microsoft-scripting-runtime-tests.ts new file mode 100644 index 0000000000..623b48368a --- /dev/null +++ b/ts-activex/microsoft-scripting-runtime-tests.ts @@ -0,0 +1,67 @@ +/// + + +//source -- https://msdn.microsoft.com/en-us/library/ebkhfaaz.aspx + + +//Generates a string describing the drive type of a given Drive object. +var showDriveType = (drive: Scripting.Drive) => { + switch (drive.DriveType) { + case Scripting.DriveTypeConst.Removable: + return 'Removeable'; + case Scripting.DriveTypeConst.Fixed: + return 'Fixecd'; + case Scripting.DriveTypeConst.Remote: + return 'Network'; + case Scripting.DriveTypeConst.CDRom: + return 'CD-ROM'; + case Scripting.DriveTypeConst.RamDisk: + return 'RAM Disk'; + default: + return 'Unknown'; + } +}; + + +//Generates a string describing the attributes of a file or folder. +var showFileAttributes = (file: Scripting.File) => { + var attr = file.Attributes; + if (attr == 0) { + return 'Normal'; + } + var attributeStrings: string[] = []; + if (attr & Scripting.FileAttribute.Directory) { attributeStrings.push('Directory'); } + if (attr & Scripting.FileAttribute.ReadOnly) { attributeStrings.push('Read-only'); } + if (attr & Scripting.FileAttribute.Hidden) { attributeStrings.push('Hidden'); } + if (attr & Scripting.FileAttribute.System) { attributeStrings.push('System'); } + if (attr & Scripting.FileAttribute.Volume) { attributeStrings.push('Volume'); } + if (attr & Scripting.FileAttribute.Archive) { attributeStrings.push('Archive'); } + if (attr & Scripting.FileAttribute.Alias) { attributeStrings.push('Alias'); } + if (attr & Scripting.FileAttribute.Compressed) { attributeStrings.push('Compressed'); } + return attributeStrings.join(','); +}; + + +//source --https://msdn.microsoft.com/en-us/library/ts2t8ybh(v=vs.84).aspx +var showFreeSpace = (drvPath: string) => { + var fso = new ActiveXObject("Scripting.FileSystemObject"); + var d = fso.GetDrive(fso.GetDriveName(drvPath)); + var s = "Drive " + drvPath + " - "; + s += d.VolumeName + "
"; + s += "Free Space: " + d.FreeSpace / 1024 + " Kbytes"; + return (s); +}; + + +//source -- https://msdn.microsoft.com/en-us/library/kaf6yaft(v=vs.84).aspx +var getALine = (filespec: string) => { + var fso = new ActiveXObject("Scripting.FileSystemObject"); + var file = fso.OpenTextFile(filespec, Scripting.IOMode.ForReading, false); + + var s = ""; + while (!file.AtEndOfLine) { + s += file.Read(1); + } + file.Close(); + return (s); +} \ No newline at end of file diff --git a/ts-activex/microsoft-scripting-runtime.d.ts b/ts-activex/microsoft-scripting-runtime.d.ts new file mode 100644 index 0000000000..0f2f734818 --- /dev/null +++ b/ts-activex/microsoft-scripting-runtime.d.ts @@ -0,0 +1,206 @@ +// Type definitions for Microsoft Scripting Runtime +// Project: https://msdn.microsoft.com/en-us/library/bstcxhf7.aspx?f=255&MSPPError=-2147217396 +// Definitions by: Zev Spitz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare namespace Scripting { + + //Enums + const enum CompareMethod { + BinaryCompare = 0, + DatabaseCompare = 2, + TextCompare = 1 + } + + const enum DriveTypeConst { + CDRom = 4, + Fixed = 2, + RamDisk = 5, + Remote = 3, + Removable = 1, + UnknownType = 0 + } + + const enum FileAttribute { + Alias = 1024, + Archive = 32, + Compressed = 2048, + Directory = 16, + Hidden = 2, + Normal = 0, + ReadOnly = 1, + System = 4, + Volume = 8 + } + + const enum IOMode { + ForAppending = 8, + ForReading = 1, + ForWriting = 2 + } + + const enum SpecialFolderConst { + SystemFolder = 1, + TemporaryFolder = 2, + WindowsFolder = 0 + } + + const enum StandardStreamTypes { + StdErr = 2, + StdIn = 0, + StdOut = 1 + } + + const enum Tristate { + TristateFalse = 0, + TristateMixed = -2, + TristateTrue = -1, + TristateUseDefault = -2 + } + + //Classes + interface Dictionary { + Add: (Key: any, Item: any) => void; + CompareMode: CompareMethod; + Count: number; + Exists: (Key: any) => boolean; + HashVal: (Key: any) => any; + Item: (Key: any) => any //Also has setter with parameters; + Items: () => any; + Key: (Key: any) => any; + Keys: () => any; + Remove: (Key: any) => void; + RemoveAll: () => void; + } + + interface Drive { + AvailableSpace: any; + DriveLetter: string; + DriveType: DriveTypeConst; + FileSystem: string; + FreeSpace: any; + IsReady: boolean; + Path: string; + RootFolder: Folder; + SerialNumber: number; + ShareName: string; + TotalSize: any; + VolumeName: string; + } + + interface Drives { + Count: number; + Item: (Key: any) => Drive; + } + + interface Encoder { + EncodeScriptFile: (szExt: string, bstrStreamIn: string, cFlags: number, bstrDefaultLang: string) => string; + } + + interface File { + Attributes: FileAttribute; + Copy: (Destination: string, OverWriteFiles?: boolean) => void; + DateCreated: VarDate; + DateLastAccessed: VarDate; + DateLastModified: VarDate; + Delete: (Force?: boolean) => void; + Drive: Drive; + Move: (Destination: string) => void; + Name: string; + OpenAsTextStream: (IOMode?: IOMode, Format?: Tristate) => TextStream; + ParentFolder: Folder; + Path: string; + ShortName: string; + ShortPath: string; + Size: any; + Type: string; + } + + interface Files { + Count: number; + Item: (Key: any) => File; + } + + interface FileSystemObject { + BuildPath: (Path: string, Name: string) => string; + CopyFile: (Source: string, Destination: string, OverWriteFiles?: boolean) => void; + CopyFolder: (Source: string, Destination: string, OverWriteFiles?: boolean) => void; + CreateFolder: (Path: string) => Folder; + CreateTextFile: (FileName: string, Overwrite?: boolean, Unicode?: boolean) => TextStream; + DeleteFile: (FileSpec: string, Force?: boolean) => void; + DeleteFolder: (FolderSpec: string, Force?: boolean) => void; + DriveExists: (DriveSpec: string) => boolean; + Drives: Drives; + FileExists: (FileSpec: string) => boolean; + FolderExists: (FolderSpec: string) => boolean; + GetAbsolutePathName: (Path: string) => string; + GetBaseName: (Path: string) => string; + GetDrive: (DriveSpec: string) => Drive; + GetDriveName: (Path: string) => string; + GetExtensionName: (Path: string) => string; + GetFile: (FilePath: string) => File; + GetFileName: (Path: string) => string; + GetFileVersion: (FileName: string) => string; + GetFolder: (FolderPath: string) => Folder; + GetParentFolderName: (Path: string) => string; + GetSpecialFolder: (SpecialFolder: SpecialFolderConst) => Folder; + GetStandardStream: (StandardStreamType: StandardStreamTypes, Unicode?: boolean) => TextStream; + GetTempName: () => string; + MoveFile: (Source: string, Destination: string) => void; + MoveFolder: (Source: string, Destination: string) => void; + OpenTextFile: (FileName: string, IOMode?: IOMode, Create?: boolean, Format?: Tristate) => TextStream; + } + + interface Folder { + Attributes: FileAttribute; + Copy: (Destination: string, OverWriteFiles?: boolean) => void; + CreateTextFile: (FileName: string, Overwrite?: boolean, Unicode?: boolean) => TextStream; + DateCreated: VarDate; + DateLastAccessed: VarDate; + DateLastModified: VarDate; + Delete: (Force?: boolean) => void; + Drive: Drive; + Files: Files; + IsRootFolder: boolean; + Move: (Destination: string) => void; + Name: string; + ParentFolder: Folder; + Path: string; + ShortName: string; + ShortPath: string; + Size: any; + SubFolders: Folders; + Type: string; + } + + interface Folders { + Add: (Name: string) => Folder; + Count: number; + Item: (Key: any) => Folder; + } + + interface TextStream { + AtEndOfLine: boolean; + AtEndOfStream: boolean; + Close: () => void; + Column: number; + Line: number; + Read: (Characters: number) => string; + ReadAll: () => string; + ReadLine: () => string; + Skip: (Characters: number) => void; + SkipLine: () => void; + Write: (Text: string) => void; + WriteBlankLines: (Lines: number) => void; + WriteLine: (Text?: string) => void; + } + +} + +interface ActiveXObject { + new (progID: 'Scripting.Dictionary'): Scripting.Dictionary; + new (progID: 'Scripting.FileSystemObject'): Scripting.FileSystemObject; + new (progID: 'Scripting.Encoder'): Scripting.Encoder; +}