Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

move folders based on their date

25 views
Skip to first unread message

Tony Logan

unread,
Feb 25, 2008, 4:36:05 PM2/25/08
to
This sounded really easy to me when I was tasked with doing it, but now I'm
bogged down and have run out of ideas. Here's a description of what I'm
trying to do:

1. On drive X, look for all folders starting with the string "delivery",
followed by a random number. There are also other folders in X called other
things that do not begin with "delivery".

2. For each of the folders starting with "delivery", if the date of the
folder equals yesterday's date, move it from X to a destination folder
(X:\archive\#yesterday's_date#\, for example). Otherwise don't move it.

It sounds easy, and I can do step #1 easy enough, but stumble with the date
issue in step #2.

I just realized one way I could solve this would be to get rid of all the
existing "delivery" folders, then just create a script to move all the
"delivery" folders and schedule that script to run at 12:01 a.m. each day,
but that seems a bit like the blunt force way of solving the issue, and I'm
betting/hoping there's a more elegant solution.

Thanks.

corey...@gmail.com

unread,
Feb 25, 2008, 6:19:54 PM2/25/08
to
Hi Tony Logan,

There are several ways to do this. First, what folder date are you
looking for? Is the date in the folder name or is it a folder
property like "date last modified" or "date created"?

If you are enumerating the folders with Scripting.FileSystemObject,
you can use the property DateLastModified or DateCreated.

Here's a good reference for Folder object methods and properties:
http://msdn2.microsoft.com/en-us/library/1c87day3(VS.85).aspx

Now, once you have that date, you can use the datediff function to
tell if it's older than x number of days:

intDays = datediff( "d",date1,date2 )

For more on datediff, visit http://msdn2.microsoft.com/en-us/library/xhtyw595(VS.85).aspx

Let me know if I you get stuck or need more help!

-Corey Thomas
MCSE/MCSA/MCDBA

On Feb 25, 4:36 pm, Tony Logan <TonyLo...@discussions.microsoft.com>
wrote:

Tony Logan

unread,
Feb 26, 2008, 1:36:00 PM2/26/08
to
Hi, Corey. Thanks for the advice. That did the trick. My code might be a tad
bloated, but for now it does what I want. By the way, it was the DateCreated
property I was looking at for each of the folders I wanted to move.

Here's the code I came up with, in case anyone wants to see it. I do some
goofing around with the date initially so I can create a folder called
mm-dd-yyyy, which is just a standard practice in our group for when we
archive things. After that I start looking at folders on S:, filter for ones
called "delivery_", then use DateDiff to determine which folders are from
yesterday, and move those folders from their current spot to the archive
folder.

' get yesterday's date, split the constituent parts & reform in desired order
' so we can name the archive folder using this date format
dt = Date - 1
' convert day to UTC 2-digit format
' (add a 0 in front of day if day is a single digit
strDay = Day(dt)
If Len(strDay) < 2 Then
strDay = "0" & strDay
End If
' convert month to UTC 2-digit format
' (add a 0 in front of month if month is a single digit
strMonth = Month(dt)
If Len(strMonth) < 2 Then
strMonth = "0" & strMonth
End If
strYear = Year(dt)
' get strTargetDate into UTC format
' (April 24, 2007 would be 20070424 in UTC format)
dt = strMonth & "-" & strDay & "-" & strYear

' creates subfolder S:\archive with yesterday's date
Set objFSO = CreateObject("Scripting.FileSystemObject")
bFolder = objFSO.FolderExists("S:\archive\" & dt)
' if folder doesn't exist, create it
If bFolder <> True Then
Set objFolder = objFSO.CreateFolder("S:\archive\" & dt)
strDestFolder = objFolder & "\"
End If

' now check folders in S: and
' move the ones beginning with "delivery_", if they meet the time/date
requirement
' in the ShowSubFolders routine below
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "S:"
Set objFolder = objFSO.GetFolder(objStartFolder)
ShowSubFolders objFSO.GetFolder(objStartFolder)

' routine to check subfolders in S:
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
' filter our subfolder search for folders that start with "delivery_"
If Left(Subfolder.Path,12) = "S:\delivery_" Then
strCreatedDate = Subfolder.DateCreated
intDays = DateDiff("d",Now, strCreatedDate)
If intDays = -1 Then
' copy folder from S: to S:\archive\##-##-#### folder
objFSO.MoveFolder Subfolder, strDestFolder
End If
End If
Next
End Sub

Dr J R Stockton

unread,
Feb 27, 2008, 12:28:13 PM2/27/08
to
In microsoft.public.scripting.vbscript message <C39AD328-E592-481C-9F9E-
5CCB19...@microsoft.com>, Tue, 26 Feb 2008 10:36:00, Tony Logan
<Tony...@discussions.microsoft.com> posted:

>' get strTargetDate into UTC format
>' (April 24, 2007 would be 20070424 in UTC format)

^^^

Where is that authoritatively defined as being UTC format? Or is it
just a typo for "ISO 8601 Basic format"?

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Tony Logan

unread,
Feb 28, 2008, 4:31:01 PM2/28/08
to
It's a typo. Forgot to update the comment when I changed the code. :-)
0 new messages