24-2 檔???

ڭ̨ϥΤUCoӽdҡAӻ WSH ɮתŪgCڭ̱q file1.txt file2.txt ŪJɮתeAAoɮתeg file3.txtAdҦpUG

lɡ]mergeTwoFiles.js^G]ǦϰUYi^
// X֨ɮ

fso = new ActiveXObject("Scripting.FileSystemObject");
file1 = "file1.txt";
file2 = "file2.txt";
file3 = "file3.txt";

// Open files
f1=fso.OpenTextFile(file1, 1 );	// Open for reading  
f2=fso.OpenTextFile(file2, 1 );	// Open for reading  
f3=fso.OpenTextFile(file3, 2, true );	// Open for writing, create  

WScript.Echo("ŪĤ@ɮסG" + file1);
c1=f1.ReadAll();
WScript.Echo("ŪĤGɮסG" + file2);
c2=f2.ReadAll();
WScript.Echo("gĤTɮסG" + file3);
f3.Write(c1);	// Write Data from first file to output
f3.Write(c2);	// Write Data from second file to output

// Close files  
f1.Close();
f2.Close();
f3.Close();

䤤 file1.txt epUG

lɡ]file1.txt^G]ǦϰUYi^
oO file1.txt eC

䤤 file2.txt epUG

lɡ]file2.txt^G]ǦϰUYi^
oO file2.txt eC

X֫xs file3.txt epUG

lɡ]file3.txt^G]ǦϰUYi^
oO file1.txt eCoO file2.txt eC

pGڭ̱``ŪɮסAiHg@Ө fileRead()ANɮפee}CAKivCBzCHUO@²檺dҡAiHŪJdҥAvC[WCƫAiXG

lɡ]fileRead01.js^G]ǦϰUYi^
// Nɮפeǰeܰ}C
WScript.Echo("CX "+WScript.ScriptName+" eå[WCơG");
WScript.Echo("");
outputArray=fileRead(WScript.ScriptName);
for (i=0; i<outputArray.length; i++)
	WScript.Echo((i+1)+". " + outputArray[i]);

// Ʃwq
function fileRead(File){
	var fso=new ActiveXObject("Scripting.FileSystemObject");
	var fid=fso.OpenTextFile(File);
	var contents=fid.ReadAll();
	fid.Close();
	var output=contents.split("\n");
	return(output);
}

榹ɮ׫ANb DOS ROLXɮתeå[JCơApUG

CX fileRead01.js eå[WCơG 1. // Nɮפeǰeܰ}C 2. WScript.Echo("CX "+WScript.ScriptName+" eå[WCơG"); 3. WScript.Echo(""); 4. outputArray=fileRead(WScript.ScriptName); 5. for (i=0; i<outputArray.length; i++) 6. WScript.Echo((i+1)+". " + outputArray[i]); 7. 8. // Ʃwq 9. function fileRead(File){ 10. var fso=new ActiveXObject("Scripting.FileSystemObject"); 11. var fid=fso.OpenTextFile(File); 12. var contents=fid.ReadAll(); 13. fid.Close(); 14. var output=contents.split("\n"); 15. return(output); 16. } ڭ̥iHϥ WSH ŪPɮ׬ʽAҦpG

lɡ]fileProp01.js^G]ǦϰUYi^
// CX WSH ɮשҨ㦳ݩ

fso = new ActiveXObject( "Scripting.FileSystemObject" );
fileObj = fso.GetFile(WScript.ScriptFullName);
WScript.Echo("WScript.ScriptFullName = " + WScript.ScriptFullName);
prop=[
	"Attributes",
	"Size",
	"DateCreated",
	"DateLastAccessed",
	"DateLastModified",
	"Drive",
	"Name",
	"ParentFolder",
	"ShortName",
	"ShortPath",
	"Type"];

for (i=0; i<prop.length; i++)
	WScript.Echo("fileObj." + prop[i] + " = " + eval("fileObj."+prop[i]));

嫬ܵGpUG

WScript.ScriptFullName = D:\users\jang\books\wsh\example\fileProp01.js fileObj.Attributes = 32 fileObj.Size = 504 fileObj.DateCreated = Tue Apr 11 19:59:05 UTC+0800 2006 fileObj.DateLastAccessed = Mon Dec 18 00:00:00 UTC+0800 2006 fileObj.DateLastModified = Mon Dec 18 14:40:08 UTC+0800 2006 fileObj.Drive = D: fileObj.Name = fileProp01.js fileObj.ParentFolder = D:\users\jang\books\wsh\example fileObj.ShortName = FILEPR~1.JS fileObj.ShortPath = D:\users\jang\books\wsh\example\FILEPR~1.JS fileObj.Type = JScript Script File

Hint
p۰ʥѤ@ɮתҦʽOHЦUŪ̷Q@QI


JScript {]pPΡGΩ WSH