Solved

VBScript to move files by size and then run another vbscript

Posted on 2008-06-09
6
659 Views
Last Modified: 2008-06-11
Two Questions:
I tried writing a vbscript that would move files depending on file size.  I would also like to run another vbscript after the first file finishes.  Below is what I have:

strTargetFolder = "C:\1kbfiles\"
strSourceFolder = "C:\testfolder\"

Dim FSO, oFolder, oFile
Set FSO = CreateObject("Scripting.FileSystemObject")
Set ofolder = FSO.GetFolder(strSourceFolder)
For Each oFile In oFolder.Files  
        If oFile.Size = 1024 Then
          'Move file
          FSO.MoveFile oFile.Path, strSourceFolder
      End If
Next
Set FSO = Nothing

The file runs but does nothing.  Any help would be appreciated.

Thank you.
0
Comment
Question by:cbones
6 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 21747733
Maybe because you are moving it to the same place that it came from?

Change this:

    FSO.MoveFile oFile.Path, strSourceFolder

To:

    FSO.MoveFile oFile.Path, strTargetFolder
0
 

Author Comment

by:cbones
ID: 21747765
Thank you.  That is what it was.  Sorry about that.   I will definitely read a little more careful next time.

After I run that script, how can I have it run another vbscript automatically once it finishes?

Thank you.
0
 
LVL 17

Expert Comment

by:Jared Luker
ID: 21747767
Hello cbones,

The way you have it writtin, it will only move a file if the file is EXACTLY 1024.  You might want to change that to

if oFile.Size > 1024 then

So that it moves files that are bigger than 1024.

Good Luck,

Jared
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 65

Expert Comment

by:RobSampson
ID: 21755361
Also, to run another script afterwards, see the last few lines....

Regards,

Rob.
strTargetFolder = "C:\1kbfiles\"
strSourceFolder = "C:\testfolder\"
 
Dim FSO, oFolder, oFile
Set FSO = CreateObject("Scripting.FileSystemObject")
Set ofolder = FSO.GetFolder(strSourceFolder)
For Each oFile In oFolder.Files  
        If oFile.Size >= 1024 Then
          'Move file
          FSO.MoveFile oFile.Path, strTargetFolder
      End If
Next
Set FSO = Nothing
 
Set objShell = CreateObject("WScript.Shell")
strScriptPath = "C:\Temp\Script2.vbs"
objShell.Run "wscript """ & strScriptPath & """", 1, False
Set objShell = Nothin

Open in new window

0
 
LVL 65

Accepted Solution

by:
RobSampson earned 250 total points
ID: 21755369
>> Set objShell = Nothin

Ha ha, sorry, that's Aussie slang.....please add a "g" to that last line....

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 21765706
Thanks for the grade.

Please remember that you can split points upon accepting an answer if you feel that other experts contributed to your solution.

Regards,

Rob.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now