Solved

VBScript to move files by size and then run another vbscript

Posted on 2008-06-09
6
660 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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