Link to home
Start Free TrialLog in
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?
Avatar of Alan_White
Alan_White
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Avatar of LanMan6401
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!
Sorry I missed the bit about the folders.  I will make it  better tomorrow morning unless someone else comes along with something better first.
Avatar of Bill Prew
Do you want to COPY files, or MOVE them?

~bp
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for your input!  Solution is now working.