Avatar of LanMan6401
LanMan6401
 asked on

Copy files and folders from a directory to a new directory with the days date.

Looking for a simple script to copy files and folders from one directory to a new one with the current days date.  A program dumps files every 15m.  I want to run a file at 11:55pm that will grab all the files and folders, dump them into a new folder with that days date.

Could someone post some code to accomplish this?
VB Script

Avatar of undefined
Last Comment
LanMan6401

8/22/2022 - Mon
Alan_White

Here is something I've just knocked up.  It's a little bit raw without any error handling but it's a start and (hopefully) functional.

I've done the "today's date folder" in reverse format because I find it easier to work with for sorting etc, but that easily be changed.
Option Explicit

Const cSourceFolder = "C:\dev\CopyFilesToDateFolder\Input"
Const cDestinationRootFolder = "C:\dev\CopyFilesToDateFolder\Output"

Dim oFSO, oFolder, oFile, sDestinationFolder
Set oFSO = CreateObject("Scripting.FileSystemObject")

sDestinationFolder = cDestinationRootFolder & "\" & Year(Now) & Right("0"&Month(Now),2) & Right("0"&Day(Now),2)
oFSO.CreateFolder sDestinationFolder

Set oFolder = oFSO.GetFolder(cSourceFolder)
For Each oFile In oFolder.Files
	oFSO.CopyFile oFile.Path, sDestinationFolder&"\"&oFile.Name
Next

Open in new window

LanMan6401

ASKER
Works great, only thing it does not grab are the folders, it grabs the files.  I needed the files moved, I just updated your CopyFile to MoveFile.  I assume that is the best way to accomplish that?

Thank you for your help!
Alan_White

Sorry I missed the bit about the folders.  I will make it  better tomorrow morning unless someone else comes along with something better first.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Bill Prew

Do you want to COPY files, or MOVE them?

~bp
SOLUTION
Bill Prew

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
LanMan6401

ASKER
Thank you for your input!  Solution is now working.