http://blog.sina.com.cn/s/blog_6f3da96501011so3.html
Sub Sample1(strPath As String, strName As String)
'strPath: path which to be searched
'strName: filename which will be created
Set WSH = CreateObject("WScript.Shell")
iFileNum = FreeFile
sTempFileName = "G:\備份\myfile.bat"
Open sTempFileName For Output As #iFileNum
Print #iFileNum, "@echo off"
Print #iFileNum, "for /f ""delims="" %%i in ('dir " & strPath & " /a-d /b /s /od') do echo %%~ti,%%~dpnxi >> G:\備份\" & strName & ".csv"
Close #iFileNum
'Invoke Batch Program".
Set wExec = WSH.Exec("%ComSpec% /c" & sTempFileName)
Do While wExec.Status = 0
DoEvents
Loop
Set wExec = Nothing
Set WSH = Nothing
End Sub
uj5u.com熱心網友回復:
僅供參考:ServerShare = "\\192.168.3.56\d$"
UserName = "somedomain\someuser"
Password = "somepassword"
Set NetworkObject = CreateObject("WScript.Network")
NetworkObject.MapNetworkDrive "", ServerShare, False, UserName, Password
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Directory = FSO.GetFolder(ServerShare)
For Each FileName In Directory.Files
WScript.Echo FileName.Name
Next
Set FileName = Nothing
Set Directory = Nothing
Set FSO = Nothing
NetworkObject.RemoveNetworkDrive ServerShare, True, False
Set NetworkObject = Nothing
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/132488.html
標籤:VBA
