JScript 使用FileSystemObject操作文件夹 练习代码

var console = {
log: function (txt) { WScript.Echo(txt); }
};


var FileSystemObject = function () {
this.fso = new ActiveXObject("Scripting.FileSystemObject");
this.GetAbsolutePathName = function (path) { return this.fso.GetAbsolutePathName(path); }
this.GetDrive = function (path) { return this.fso.GetDrive(path); }
this.GetDriveName = function (path) { return this.fso.GetDriveName(path); }
this.GetBaseName = function (path) { return this.fso.GetBaseName(path); }
this.GetExtensionName = function (path) { return this.fso.GetExtensionName(path); }
this.GetFile = function (filespec) { return this.fso.GetFile(filespec); }
this.GetFileName = function (pathspec) { return this.fso.GetFileName(pathspec); }
this.GetFileVersion = function (pathspec) { return this.fso.GetFileVersion(pathspec); }
this.GetFolder = function (folderspec) { return this.fso.GetFolder(folderspec); }
this.GetParentFolderName = function (path) { return this.fso.GetParentFolderName(path); }
this.GetTempName = function () { return this.fso.GetTempName(); }
this.GetWindowsFolder = function () { return this.fso.GetSpecialFolder(0); }
this.GetSystemFolder = function () { return this.fso.GetSpecialFolder(1); }
this.GetTemporaryFolder = function () { return this.fso.GetSpecialFolder(2); }
};

 

var fso, tempfile;
fso = new ActiveXObject("Scripting.FileSystemObject");

function CreateTempFile()
{
   var tfolder, tfile, tname, fname, TemporaryFolder = 2;
   tfolder = fso.GetSpecialFolder(TemporaryFolder);
   tname = fso.GetTempName();
   tfile = tfolder.CreateTextFile(tname);
   return(tfile);
}
tempfile = CreateTempFile();
tempfile.writeline("Hello World");
tempfile.close();
posted @ 2023-08-16 17:32  小风风的博客  阅读(20)  评论(0编辑  收藏  举报