Skip to content

Commit a96e3ac

Browse files
committed
Initial commit
0 parents  commit a96e3ac

4 files changed

+98
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Search directory for a specific keyword or a file type and move files to new location using VBScript and batch file
2+
3+
###### Date Created: January 17, 2019
4+
###### Author: Ronknight
5+
###### License: MIT
6+
###### Tags: Search, Move, Files, Images, VBScript, vbs, Batch, bat, CLI
7+
###### Script: search-move-files.vbs
8+
###### Description: Search all files that has a filename as the keyword from a source folder and move files to the new destination folder
9+
10+
---
11+
12+
## Instructions
13+
14+
First, You’ll start by editing the **search-move-files.vbs** file.
15+
16+
1. Open the vbs file using your favorite file editor.
17+
2. Change the **SourceFolder** path to your *SourceFolder* path. Example: C:\User\Ron\Downloads\
18+
3. Change the **DestFolder** path to your *DestFolder* path. Example: C:\User\Ron\Desktop\New Folder\
19+
4. Change **keyword** to your *new-keyword* Examples: .xlsx or .jpg or image
20+
5. Save and close *search-move-files.vbs*.
21+
---
22+
23+
Secondly, edit the **Run-Seach-Move-Program.bat** file.
24+
25+
1. Open the BATCH file using your favorite file editor.
26+
2. Update the **path** of your vbs file.
27+
3. Save and close *Run-Seach-Move-Program.bat*.
28+
---
29+
30+
Lastly, Run the Program
31+
32+
1. Double cLick **Run-Seach-Move-Program.bat** to execute the vbs program.
33+
2. Wait for vbs to finish the task.
34+
3. Watch as windows copies your files to your new location.

Run-Seach-Move-Program.bat

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
:: Author: Ronknight
2+
:: Date: 1/17/19
3+
:: License: MIT
4+
:: Tags: Batch, bat, vbs, VBScript
5+
6+
@echo off
7+
pushd %~dp0
8+
:: change path of seach-move-files.vbs, example c:\Plus\search-move-files\search-move-files.vbs
9+
start /b "" cscript c:\search-move-files.vbs

search-move-files.vbs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)