Avatar of 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

8/22/2022 - Mon

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

Open in new window


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!

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?

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

Thank you for your input!  Solution is now working.