Computing.Net > Forums > Programming > Sort files in vbscript

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Sort files in vbscript

Reply to Message Icon

Name: Crossroad
Date: June 27, 2007 at 17:55:26 Pacific
OS: W2k
CPU/Ram: Pentium4
Product: Intel
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: June 28, 2007 at 18:59:05 Pacific
Reply:

Untested .VBS:

For Each d In CreateObject("Scripting.FileSystemObject").GetFolder("c:\food_products").SubFolders
sMoveTo = SNewLoc(d)
If sMoveTo <> "" Then _
d.Move sMoveTo
Next

Function 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


0

Response Number 2
Name: Crossroad
Date: June 28, 2007 at 19:46:03 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Sort files in vbscript

Sort a text file in VBScript www.computing.net/answers/programming/sort-a-text-file-in-vbscript/7334.html

Run/Exec .exe file in VBScript www.computing.net/answers/programming/runexec-exe-file-in-vbscript/5614.html

Deleting files using VBscript www.computing.net/answers/programming/deleting-files-using-vbscript/12660.html