Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBScript to move files by size and then run another vbscript

Posted on 2008-06-09
6
Medium Priority
?
664 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
Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

 
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 1000 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

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

715 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