资源描述:
《Windows脚本编程核心技术精解Chapter07.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、4684-8ch07.f.qc3/3/009:34AMPage219Chapter7AccessingtheFileSystemInThisChapterAccessdrives,folders,andindividualfilesPeekintoanyfile,andchangingfilecontentsatwillDeterminefreespaceondrives,andovercomethe2GBbugSearchtheentireharddriveforoutdatedfilesoremptyfoldersrecursivelyTheW
2、indowsScriptingHostcomeswithasecretscriptextension,calledScripting.FileSystemObject.Thisobjectgrantsfullaccesstotheentirefilesystem.Inthischapter,you’lldiscoverhowtopeekintofiles,copy,move,deleteandcreatenewfilesfromscratch.Inaddition,I’llshowyousomeworkaroundstocorrectlydealwithd
3、rivesizesgreaterthan2GBFindingtheSecretBackdoortotheFileSystemThefilesystemisoneofthemostinterestingareasofyourcomputer.It’swhereallofyourdataisstored,andtherearenumeroustasksthatscriptscanhandleforyou,includingreorganizingdata,findingorphanfiles,doingbackups,andmore.Howdoyougetac
4、cesstoyourfiles?BoththeWSHandVBScriptlackfilesystemcommands.There’snowaytoopenfiles,deletedata,orcopyfolders.However,thismakesperfectsensebecausebothWSHandVBScriptaredesignedasplatform-independenttechnologies.Thefilesystem,incontrast,isveryspecial,anditstechnologycanvaryfromoperat
5、ingsystemtooperatingsystem.Still,yourscriptshavefullaccesstoyourfilesystem.Microsofthasplacedallthenecessarycommandsintoaseparatemodule.scrrun.dllisautomaticallyregisteredasaScripting.FileSystemObjectCOMcomponent,andwheneveryouneedfilesystemsupport,justincludeareferencetothisobjec
6、tinyourscripts.4684-8ch07.f.qc3/3/009:34AMPage220220PartII:ConqueringtheFileSystem■■AccessingadriveWhere’sthesecretbackdoortoyourfilesystem?Actually,therearemanydoors.OneistogetaccesstoanyoneofyourdrivesusingGetDrive:‘7-1.VBS‘getaccesstofilesystemcommands:setfs=CreateObject(“Scrip
7、ting.FileSystemObject”)setdrivec=fs.GetDrive(“C:”)MsgBoxTypeName(drivec)emptyspace=drivec.AvailableSpaceMsgBox“AvaialableonC::“&_FormatNumber(emptyspace/1024^2,1)&“MB”ThissimplescriptaccessesdriveC:andreturnsaDriveobject.TheDriveobjectcontainsmanyusefulpropertiesandmethods.TheA
8、vailableSpaceproperty,forexample,