Home > Software engineering >  Each master, brother, help! I need to run on Windows script (see here is the script file area was se
Each master, brother, help! I need to run on Windows script (see here is the script file area was se

Time:11-22

To realize the function of the script is like this:
For example:
Under the folder a b. there are three files, c.d, e. xt. And a folder under several files
There are a lot of file folder b;
Asked to delete folders under b all file and folder a include a folder in the file with the same (or delete folders under the name of b. b, c.d, e. xt file, also there may not be possible).
Need to take into account the issue of nesting child folder

Namely I copy some files in the past, now regret it want to delete! Because the file is more, I a little bit, a little dizzy, time also use make up!

CodePudding user response:

I got a this, but can't access to a folder in the file list

Dim ofso, File
Dim PathA, PathB
Dim FilesInPathA

The Set ofso=CreateObject (" Scripting. FileSystemObject ")

'get the path A list of files
The Set PathA=ofso. GetFolder (" C: \ Users \ \ Administrator \ Desktop \ pack meshes ")
For Each File In PathA. Files
FilesInPathA=FilesInPathA & amp; "|" & amp; File. The Name
Next

'get under the path B file list
The Set PathB=ofso. GetFolder (" C: \ Users/Administrator/Desktop/meshes ")
For Each File In PathB. Files
. If InStr (FilesInPathA, the File Name) Then 'whether this File under the path A there
File. Delete if there is a True 'Delete the
End the If
Next

The Set of fso=Nothing

CodePudding user response:

Write well, code is as follows:
 
The Set of fso=createobject (" scripting. Filesystemobject ")
Curdir=fso. Getparentfoldername (wscript. Scriptfullname)
DirA=fso. Buildpath (curdir, "a")
DirB=fso. Buildpath (curdir, "b")

The Set dict=createobject (" scripting. The dictionary ")
Addfilenames fso. Getfolder (dirA)
Removefiles fso. Getfolder (dirB)
Msgbox "Done!"

Sub AddFileNames (ByVal objFolder)
For Each objfile In objfolder. Files
Dict. Item (objfile. Name)=null
Next
For Each objsubfolder objfolder. In subfolders
Addfilenames objsubfolder
Next
End Sub

Sub RemoveFiles (ByVal objFolder)
For Each objfile In objfolder. Files
If dict. The exists (objfile. Name) Then
Fso. Deletefile objfile path, True
End the If
Next
For Each objsubfolder objfolder. In subfolders
Removefiles objsubfolder
Next
End Sub

Download address:
Link: https://pan.baidu.com/s/1nYH7LPdlcPSvaIT8BoP4zw
43 tr
extraction code:
  •  Tags:  
  • VBA
  • Related