24-3 ?®é??‡ç?碟æ??•ç?

­Y­nÅã¥Ü¬Y¤@­Ó¸ê®Æ§¨ªº¤j¤p¡A¥i¥H¨Ï¥Î¡A½d¨Ò¦p¤U¡G

­ì©lÀÉ¡]dirSize01.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
// Åã¥ÜÀÉ®×§¨ªº¤j¤p

fso = new ActiveXObject("Scripting.FileSystemObject");
folderPath = "c:\\windows\\system32";	// ·|¦³Åv­­°ÝÃD
folderPath = "d:\\users\\jang\\matlab\\toolbox\\machineLearning";
folderObj = fso.GetFolder(folderPath);
WScript.Echo(folderPath + " ¥Ø¿ýªº¤j¤p¬O " + folderObj.Size + " bytes.");

°õ¦æ¤W­zµ{¦¡«á¡A¨å«¬Åã¥Üµ²ªG¦p¤U¡G

c:\windows\system32 ¥Ø¿ýªº¤j¤p¬O 1116543626 bytes.

¥t¤@­Ó±`¨£ªºÀ³¥Î¡A«h¬OºÞ²zªÌ­nÀˬd¨C­Ó¤H¦b d:/users ¤U­±©Ò¦û¥ÎªººÏºÐ¤j¤p¡A¥i¨Ï¥Î¤U¦C½d¨Ò¨Ó¹F¦¨¡G

­ì©lÀÉ¡]dirSize02.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
// Get directory sizes under d:/users

topDirName="d:/users";
fso = WScript.CreateObject("Scripting.FileSystemObject");
dirObj = fso.GetFolder(topDirName);

subFolderList=new Enumerator(dirObj.SubFolders);
for (subFolderList.moveFirst(); !subFolderList.atEnd(); subFolderList.moveNext()){
	dirName=subFolderList.item().name;
	dirSize=subFolderList.item().Size;
	WScript.Echo(dirName+" ===> "+dirSize+" bytes");
}

°õ¦æ¤W­zµ{¦¡«á¡A¨å«¬Åã¥Üµ²ªG¦p¤U¡G

classifiedEmailBackup ===> 4737324602 bytes jang ===> 54129835620 bytes jang2 ===> 91708923441 bytes Windows Live Mail ===> 16105564241 bytes ¡]½Ðª`·N¡G¥Ñ©ó¤W­z½d¨Ò¥²¶·Àˬd¨C¤@­Ó¤l¥Ø¿ý©Ò¦û¥ÎªºªÅ¶¡¡A©Ò¥H°õ¦æ®É¶¡·|¤ñ¸û¤[¡C¡^

§Ú­Ì¥i¥H¨Ï¥Î WSH ¨ÓÅã¥Ü¥Ø«e¤u§@¥Ø¿ý¡A©Î¬O§ïÅܥثe¤u§@¥Ø¿ý¡A¦p¤U¡G

­ì©lÀÉ¡]dir01.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
// ¨Ï¥Î WSH ¨ÓÅã¥Ü¥Ø«e¤u§@¥Ø¿ý¡A¤Î§ïÅܥثe¤u§@¥Ø¿ý

wshShell=new ActiveXObject("WScript.Shell");
WScript.Echo("¥Ø«e¤u§@¥Ø¿ý¡G"+wshShell.CurrentDirectory);
wshShell.CurrentDirectory = "c:\\windows\\temp";
WScript.Echo("§ïÅܥثe¤u§@¥Ø¿ý¦Ü¡G"+wshShell.CurrentDirectory);

¨å«¬Åã¥Üµ²ªG¦p¤U¡G

¥Ø«e¤u§@¥Ø¿ý¡GD:\users\jang\books\wsh\example §ïÅܥثe¤u§@¥Ø¿ý¦Ü¡Gc:\windows\temp

¤U¦C³o­Ó½d¨Ò¡A¦C¥X c:\windows\temp ¥Ø¿ý¤Uªº©Ò¦³ÀɮסA¦p¤U¡G

­ì©lÀÉ¡]fileList01.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
// ¦C¥X¤@­Ó¯S©w¥Ø¿ý¤Uªº©Ò¦³ÀÉ®×

fso = new ActiveXObject("Scripting.FileSystemObject");
folderPath="c:\\windows\\temp";
fsoFolder = fso.GetFolder(folderPath);
fileList = new Enumerator(fsoFolder.Files);
WScript.Echo("Files under \""+folderPath+"\":");
for (fileList.moveFirst(); !fileList.atEnd(); fileList.moveNext())
	WScript.Echo(fileList.item());

¥Ñ©ó¿é¥X¸ûªø¡A¦b¦¹¤£ÂئC¡AŪªÌ½Ð¦Û¦æ¸Õ¬Ý¬Ý¦¹½d¨Ò¡C

¤U¦C³o­Ó½d¨Ò¡A¦C¥XºÏºÐ¾÷¤Î¨ä¬ÛÃö©Ê½è¡G

­ì©lÀÉ¡]driveList01.js¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
// ¦C¥X©Ò¦³ªººÏºÐ¾÷

fso = new ActiveXObject("Scripting.FileSystemObject");
driveTypes=["¥¼ª¾Ãþ«¬", "©â¨ú¦¡", "µwºÐ", "ºô¸ôºÏºÐ¾÷", "¥úºÐ", "µêÀÀºÏºÐ"];
drives = new Enumerator(fso.Drives);		// Create Enumerator on Drives.
for (; !drives.atEnd(); drives.moveNext()) {	// Enumerate drives collection.
	x = drives.item();
	WScript.Echo(x.DriveLetter+":")
	WScript.Echo("\tx.DriveType = " + x.DriveType + " (" + driveTypes[x.DriveType] + ")");
	WScript.Echo("\tx.ShareName = " + x.ShareName);
	WScript.Echo("\tx.IsReady = " + x.IsReady);
	if (x.IsReady){
		WScript.Echo("	x.VolumeName = " + x.VolumeName);
		WScript.Echo("	x.AvailableSpace = " + x.AvailableSpace + " Bytes");
	}
}

¨å«¬Åã¥Üµ²ªG¦p¤U¡G

C: x.DriveType = 2 (µwºÐ) x.ShareName = x.IsReady = true x.VolumeName = x.AvailableSpace = 24901296128 Bytes D: x.DriveType = 2 (µwºÐ) x.ShareName = x.IsReady = true x.VolumeName = ·s¼WºÏºÐ°Ï x.AvailableSpace = 17471188992 Bytes E: x.DriveType = 4 (¥úºÐ) x.ShareName = x.IsReady = true x.VolumeName = hp LaserJet 3800 x.AvailableSpace = 0 Bytes ...
JScript µ{¦¡³]­p»PÀ³¥Î¡G¥Î©ó³æ¾÷ªº WSH Àô¹Ò