Solved

VBScript to move files by size and then run another vbscript

Posted on 2008-06-09
6
662 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 86

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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PowerShell and cisco ios 3 70
Scripting 4 37
XSLT to pick out a particular element and then pick out all following siblings 4 22
T-SQL Query 9 37
In this post we will learn different types of Android Layout and some basics of an Android App.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to count occurrences of each item in an array.
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.

710 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