1
+ ' Date Created: January 17, 2019
2
+ ' Author: Ronknight
3
+ ' Script: search-move-files.vbs
4
+ ' Description: Search all files that has a filename as the keyword from a source folder and move files to the new destination folder
5
+
6
+ dim objFSO, SourceFolder, DestFolder, Keyword, i
7
+
8
+ 'Path
9
+ 'change sourcepath example "C:\Users\Ron\Downloads\"
10
+ SourceFolder = "Enter new path here"
11
+ 'change sourcepath example "C:\Users\Ron\Desktop\Backup\"
12
+ DestFolder = "Enter new path here"
13
+
14
+ 'Variables
15
+ 'Enter search keyword here, example "wc-product-export" or ".xls" or ".jpg"
16
+ Keyword = "Enter keyword here"
17
+ i = 0
18
+
19
+ 'Objects
20
+ set objFSO = CreateObject( "scripting.Filesystemobject" )
21
+ set objFolder = objFSO.GetFolder(SourceFolder)
22
+
23
+ 'Execute Main Function
24
+ Main objFSO.GetFolder(SourceFolder)
25
+ 'Prompt end of Loop
26
+ Wscript.Echo "Exiting program..."
27
+
28
+ Sub Main(objFolder)
29
+ 'List all Subfolder form Source Directory
30
+ For Each File in objFolder.Files
31
+ x = objFSO.GetBasename(File)
32
+ 'Search Keyword
33
+ If instr(lcase(x), Keyword) > 0 then
34
+ i = i+ 1
35
+ 'Delete file if it already exists
36
+ If objFSO.Fileexists(DestFolder & "\" & File.name) then
37
+ objFSO.deleteFile DestFolder & "\" & File.name, true
38
+ End If
39
+ 'Move file to new location
40
+ Wscript.Echo "File moved: " & File.Name
41
+ objFSO.MoveFile SourceFolder & "\" & File.name, DestFolder
42
+ End If
43
+ Next
44
+
45
+ If i> 0 then
46
+ 'Prompt end of process and show destination folder
47
+ Wscript.Echo "Moving of files completed..."
48
+ Wscript.Echo i & " Files moved to : " & DestFolder
49
+ Wscript.quit()
50
+ End If
51
+ 'Prompt if keyword not found
52
+ Wscript.Echo "No match found..."
53
+ End Sub
0 commit comments