Solved

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

Posted on 2014-11-22
5
88 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
[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
  • 3
  • 2
5 Comments
 
LVL 54

Expert Comment

by:Bill Prew
ID: 40459789
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
ID: 40459800
yes c:\scan
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 40459826
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
ID: 40462534
Thanks so much Bill!!   this worked
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 40462758
Great, glad that was useful.

~bp
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Server 2012 management. 5 54
VBA code for SubFolders 11 47
Cross checking component service dlls 2 35
How to set PAUSE for this script ? 5 20
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 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