Home > Software engineering >  How to use the batch traversal folder
How to use the batch traversal folder

Time:10-17


http://blog.sina.com.cn/s/blog_6f3da96501011so3.html
Sub Sample1 (strPath As String, strName As String)
'strPath: the path which to be searched
'strName: filename which will be created

Set the WSH=CreateObject (" WScript. Shell ")
IFileNum=FreeFile
Backup sTempFileName="G: \ \ myfile bat"
The Open sTempFileName For Output As # iFileNum
Print # iFileNum, "@ echo off"
Print # iFileNum, "for/f" "delims=" "% % I in (' dir" & amp; StrPath & amp; "A - d/b/s/od ') ~ ti do echo % % % % ~ dpnxi & gt;> G: \ \ backup "& amp; StrName & amp; "CSV"
Close # iFileNum

'the Invoke Batch Program ".
ComSpec Set wExec=WSH. Exec (" % %/c "& amp; STempFileName)
The Do While wExec. Status=0
DoEvents
Loop
The Set wExec=Nothing
Set the WSH=Nothing

End Sub

CodePudding user response:

Fyi:
 ServerShare=\ \ "192.168.3.56 \ d $" 
The UserName="somedomain \ someuser"
Password="somepassword"

The Set NetworkObject=CreateObject (" work "WScript.Net

NetworkObject. MapNetworkDrive ", "ServerShare, False, UserName, Password,"

The Set of FSO=CreateObject (" Scripting. FileSystemObject ")
Set the Directory=FSO. GetFolder (ServerShare)
For Each FileName In the Directory. The Files
WScript. Echo FileName. The Name
Next
Set the FileName=Nothing
Set the Directory=Nothing
The Set of FSO=Nothing

NetworkObject. RemoveNetworkDrive ServerShare, True, False

The Set NetworkObject=Nothing
  •  Tags:  
  • VBA
  • Related