Solved

VBScript to move files by size and then run another vbscript

Posted on 2008-06-09
6
656 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

706 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

18 Experts available now in Live!

Get 1:1 Help Now