jScript FileSystemObject基本操作

写文件
var fso;
fso = new ActiveXObject("Scripting.FileSystemObject");
a = fso.CreateTextFile("d:\\testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();


复制文件
var fso, f;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.CreateTextFile("c:\\jscript\\testfile.txt", true);
f.WriteLine("This is a test.--HelloWorld");
f.Close();
f = fso.GetFile("c:\\jscript\\testfile.txt");
f.Copy("c:\\jscript\\copy\\test2.txt");


复制文件夹
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFile ("c:\\mydocuments\\letters\\*.doc", "c:\\tempfolder\\")


删除文件
var fso, f;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.CreateTextFile("c:\\testfile.txt", true);
f.WriteLine("This is a test.");
f.Close();
f = fso.GetFile("c:\\testfile.txt");
f.Delete();


遍历数据
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ForReading = 1, ForWriting = 2, ForAppending = 8;
var file = "文件名";
if(fso.fileExists(file)){
	var txt = fso.OpenTextFile(file,ForReading);
	//遍历数据
	while (!txt.AtEndOfStream){
		data = txt.ReadLine();
	}
	txt.close();
}

你可能感兴趣的:(jscript)