Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi All !
I'd like to create a vbscript that will move(sort) some files of some folders to an
other folder depending of a string search result.For example let say I have the following files under the following folders;
c:\food_products\folderA
- itemA1.doc
- itemA2.doc
- anyname.txt (this text file would contain the "Back Order" string in it)c:\food_products\folderB
- itemB1.doc
- itemB2.doc
- anyname.txt (this text file would contain the "Item Sold" string in it)and so on...
Depending of the string search results, all files in the same folder as the text file containing the string "Back Order" would be moved to c:\Back_Order\previous child foldername
and any other files in the same folder as the text file containing the string "Item sold" would be moved to c:\Item_Sold\previous child foldername
Any ideas appreciated.
Thanks

Untested .VBS:
For Each d In CreateObject("Scripting.FileSystemObject").GetFolder("c:\food_products").SubFolders
sMoveTo = SNewLoc(d)
If sMoveTo <> "" Then _
d.Move sMoveTo
NextFunction SNewLoc(ByRef oDir)
SNewLoc = ""
For Each f In oDir.Files
If LCase(Right(f.Name, 4)) = ".txt" Then
With f.OpenAsTextStream(1)
Do Until .AtEndOfStream
Select Case LCase(Trim(.ReadLine))
Case "back order"
SNewLoc = "c:\Back_Order\" & oDir.Name
Exit Function
Case "item sold"
SNewLoc = "c:\Item_Sold\" & oDir.Name
Exit Function
End Select
Loop
End With
End If
Next
End Function

Hi Razor, thanks for your usual quick reply.
There is some syntax and command errors but at least I have something to start with.
I will now start debugging and let you know when the script is error free.
Again, thanks for your help, I do appreciate it.
Crossroad

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |