Solved

Need a VB script that will create a folder and move files.

Posted on 2014-11-22
5
83 Views
Last Modified: 2014-11-24
I am looking for some assistance with a VBS script.

The script will be scheduled to run nightly and do the following

Create a subfolder with yesterdays date (example today is 11_23_2014 the folder created would be 11_22_2014)

The move all files from c:\scan\ to the Newly created folder


This does not sound hard but it is kicking my rear.
0
Comment
Question by:JaysonJackson
  • 3
  • 2
5 Comments
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Under what folder would you like the dated daily folders created?

I assume there are only files and not subfolders to move from C:\SCAN?

~bp
0
 

Author Comment

by:JaysonJackson
Comment Utility
yes c:\scan
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
Give this a try and see if it is acceptable, it should do what you described.

' Specify folder to work in
strBaseDir = "C:\Scan"

' Create filesystem object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Quit if specified folder doesn't exist
If Not objFSO.FolderExists(strBaseDir & "\") Then 
   Wscript.Echo "Base folder missing, ending."
   Wscript.Quit
End If

' Calculate yesterdays date, format as MM_DD_YYYY
dtmValue = DateAdd("d", -1, Now())
strDate = LPad(Month(dtmValue), 2, "0") & "_" & LPad(Day(dtmValue), 2, "0") & "_" & Year(dtmValue)

' Create destination folder with yesterdays date
strDestDir = strBaseDir & "\" & strDate
objFSO.CreateFolder strDestDir

' Move all files in base directory to dated folder
objFSO.MoveFile strBaseDir & "\*.*", strDestDir

' Done
Set objFSO = Nothing

' Left pad a string to any length with a specified character
Function LPad( strText, intLen, chrPad )
   LPad = Right( String( intLen, chrPad ) & strText, intLen )
End Function

Open in new window

~bp
0
 

Author Closing Comment

by:JaysonJackson
Comment Utility
Thanks so much Bill!!   this worked
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Great, glad that was useful.

~bp
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

12 Experts available now in Live!

Get 1:1 Help Now