[Scripting] Creating a folder and moving files based on time stamps.

I've never done anything with vb but I've been given a task I'm not quite sure how to do.

I have a csv text file with three columns, JobName, StartDateTime and StopDateTime. I am trying to make a script that will look at the JobName, and see the times it starts and stops then take any files within that time frame and put it into a folder that has the JobName. I have sort of a frame work but I am not having any success in finishing this.

For Each f In CreateObject("Scripting.FileSystemObject").GetFolder(".").Files If f.DateCreated <= Now - 1 Then _ f.Move "c:\someOtherFolder\" Next 'f

I don't have to do this in vbscript, I can do it anyway that works (Powershell, dos, Cygwin), I was just suggested to make it this way.

Am I headed in the right direction? Should I be doing something else? Any help is appreciated.

Take a look at a program called Belvedere. I believe that it can do that for you with its settings.

A good way to start is often to jot down some pseudo code that solves the problem. Writing the actual code then becomes pretty straight forward. Something like this for example.

For each row in CSV file: Read JobName, StartDateTime and StopDateTime For each file in base dir: Read file creation date If file creation date is between StartDateTime and StopDateTime: If a dir named JobName doesn't exist: Create dir named JobName Move file to JobName

I'm not sure that's as easy as you might think. For one thing, your data may not be sane... do all jobs stop before the next job starts? If you have any overlapping date ranges, then files may not map uniquely to jobs.

Second, there are three different file times -- creation time, modification time, and last access time. If a file was first created during Job 17, but modified during Job 19, does it still belong to 17?

Overall, I'd probably approach it by first verifying data sanity. If I could get absolutely unique times for each job, so that no file could belong to more than one, then I'd know that 'stop time' was now superfluous.... if all jobs stop before another job starts, then you don't need a stop time. If, as is more likely, there's a lot of overlap, then your logic doesn't work, and you'll have to rethink it.

tl;dr version of above: if the thought of deleting the 'job end' column fills you with fear, then your algorithm as stated won't work reliably.

I started to explain how you'd approach the problem, but I realize that I'm just too out of date on Visual Basic to be very helpful. I think I'll just confuse you. If nobody else has any suggestions, and you verify that you do indeed have sane data and can indeed run your algorithm as specified, I'll try to give you at least an overview of how to approach the problem, but you can expect to spend quite a lot of time learning the ropes to get this working.

I'm not sure I was clear enough about explaining the time problem.

Consider that you have three jobs:

Job Start Date End Date Example 1 12/01/2010 12/15/2010 Example 2 12/07/2010 12/21/2010 Example 3 12/14/2010 12/28/2010

If you have a file that was created on 12/10/2010, it could belong to either Example 1 or Example 2. It it was created on 12/14/2010, it could belong to all three.

Do the files themselves have a time stamp of some sort in their name? Like Filexyz_20110101.txt ? That would make it a bit easier than relying on date flags of the file itself since I've run into situations where the modified and last accessed date where earlier than create.