fso創建文件夾
Ⅰ vbs鍒涘緩鏂囦歡澶
dimpathname,filename,fso,read,str,filepath
setfso=createobject("scripting.filesystemobject")
pathname="path.txt"
str="ShutdownScript emotecomputer.txt"
iffso.fileexists(pathname)=true鑼勬福then'鍏堟潵鍒ゆ柇瀹冩槸涓涓鏈夋晥鐨勮礬寰+鏂囦歡,濡傛灉鎴愮珛,浠ヤ笅鍧囨寜姝e父紼嬪簭鎵ц
read=fso.opentextfile(pathname).readall'璇誨彇鍏ㄦ枃
foreachiinsplit(read,vbcrlf)'閬嶅巻鍏ㄦ枃姣忚岀殑鍐呭
ifinstr(right(i,1),"")=0thenfilename=i&""&strelsefilename=i&str'鍦ㄦ墽琛屼笅闈浠g爜涔嬪墠鍏堣繘棰ゆ瘉鎮勮屾牸寮忓寲澶勭悊鏂囨湰
filepath=left(filename,instrrev(filename,""))'鍒嗙昏礬寰
iffso.folderexists(filepath)=falsethenfso.createfolderfilepath'濡傛灉璺寰勫瓨鍦ㄥ垯鍒涘緩鏂囦歡澶
iffso.fileexists(filename)=falsethenfso.createtextfile(filename).write"test"'濡傛灉鏂囦歡浣欏惖瀛樺湪鍒欏壋寤烘枃浠跺啓鍏test
next
endif
Ⅱ 鐢╒BS閫氳繃for寰鐜鎵歸噺鍒涘緩鏂囦歡澶瑰拰鏂囦歡
Sub locCreateResultFolder()
Dim fso
Dim i,vPath
Set fso = CreateObject("Scripting.FileSystemObject")
vPath = "C:\Program Files\personal\"
fso.CreateFolder "C:\Program Files\personal\"
fso.CreateFolder "C:\Program Files\personal\testFolder"
for i=0 to 100
If Not fso.folderexists(vPath&"testFolder\"&i) Then
fso.CreateFolder(vPath&"testFolder\"&i)
End If
next
End Sub
call locCreateResultFolder
'createfolder鏂規硶鍦ㄨ岃皚鍒涘緩鐩褰曟椂錛屼笂灞傜洰褰曞繀欏誨瓨鍦ㄣ
'鑰呰春渚嬪傚壋寤 c:\1\2錛屽傛灉c鐩樹笅娌℃湁鐩褰1錛岄偅棣栧甫媧句箞灝變細鍑洪敊錛堜笉鍒涘緩鐩褰2錛夈
Ⅲ VBS濡備綍閫氳繃FSO鍒涘緩鏃ユ湡鍛藉悕鐨勬枃浠跺す錛屽苟鍦ㄦ枃浠跺す閲屽壋寤烘椂闂村懡鍚嶇殑鏂囨。銆
Const ForReading = 1, ForWriting = 2, ForAppending = 8
AA = "D:\鏃﹀瓭"&FormatDateTime(Date, 1)
BB = AA & "\"& hour(time) & Minute(time) & Second(time)&".txt"
Set fso = CreateObject("妯℃竻紼縎cripting.FileSystemObject")
msgbox fso.FolderExists(AA)
IF fso.FolderExists(AA)=FALSE THEN
Set f = fso.CreateFolder(AA)
END IF
Set f = fso.OpenTextFile(BB, ForWriting, True)
f.Write "鍡錛屼綘濂斤紒"姝g噧
f.Close