Last modification date of a file.

Hi,

I am desperate looking for some kind of utility that can do the following for me :

All files that are older than 1/1/2007 should be erased from my servers before 27/12. I do not have the time to check +18.000 files if they really can be deleted. I would like to modify the last date the files where modified to another date. But this filedate should be random between 1/1/2007 and 31/12/2007

Does anyone have an idea?

Kind regards,
Alain.
KreativaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul MacDonaldDirector, Information SystemsCommented:
Older as in creation time or modified time?
0
Bill PrewCommented:
Can you clarify a little bit, or at least confirm what I think you need.

You are concerned that if you do nothing, on 12/27/2011 all files "older" than 1/1/2007 will automatically be deleted.  To prevent that you would like to locate those files now, and change their date stamp to something in the range of 1/1/2007 to 12/32/2007, but pick that date randomly.

You do need to clarify if you mean "last modified date" or "created date" of these files.

~bp
0
Bill PrewCommented:
To change a files date stamp in MS DOS you would need an addon utility like "touch".  There are some free ones out there, but not sure if using one of these is okay for you?

If not, then it can be done in a VB script, would that be okay?

~bp
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Paul MacDonaldDirector, Information SystemsCommented:
Re-reading this, you don't seem to need a batch file, which is what I'd initially presumed.  

You can take a look at this: http://www.deletefilesbydate.com/ or, if you're on Windows, you can do a search in Windows Explorer for files older than a certain date and delete them that way.
0
Steve KnightIT ConsultancyCommented:
Here is a VBScript version of "touch" I wrote which will update date / time of a file:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/Q_27441352.html

We could combine that with a) a check for files older than 2007, e.g.:

http://scripts.dragon-it.co.uk/links/batch-delete-files-older-than

and then take a base date of 1/1/2007 and add 1-365 days to it:

Haven't got time to put it all together at the moment sorry, (many) other things on the go but thought you want that bit to set the file time to an arbritary time.


Steve
0
Steve KnightIT ConsultancyCommented:
Curious here mind... do we presume you are trying to get around an admin imposed automatic archiving of "old" files by any chance - which of course it pretty idiotic, files are often accessed but not modified IMO...

Steve
0
Bill PrewCommented:
Sounded like it to me Steve...

~bp
0
KreativaAuthor Commented:
Indeed, We are A global (car make) player. And we are forced to remove all files older than 01/01/2007 on our servers.

But I already checked and this resulted in +18.000 files that where older than 01/01/2007.

I first have to check those files and do not have the time (this year) to do so. I would therefore like to have the create and last modified date to be altered to a random date between 01/01/2007 - 31/12/2007 this way I have another year to actually clean op those files.

Alain.
0
Steve KnightIT ConsultancyCommented:
Baby sitters arriving in 10 minutes for rare night out with wife so shan't be writing any code this evening ;)

Sure Bill or others will assist, if not will look back tomorrow.

Steve
0
KreativaAuthor Commented:
Have fun Steve! I can wait another day ;)

Alain.
0
Bill PrewCommented:
Okay, I think this should be pretty close to what you need, give it a try.

' Initialize random numbers
Randomize

' Create needed objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application") 

' Set cutoff date, looking for files before this
datCutoff = DateSerial(2007, 1, 1) + TimeSerial(0, 0, 0)

' Call recursive routine to find and touch old files
FindFiles objFSO.GetFolder("c:\"), datCutoff

Sub FindFiles(objFolder, datBefore)
    ' Check all files in this folder
    For Each objFile In objFolder.Files
        ' See if it is before the cutoff date
        If objfile.DateLastModified < datBefore Then
            ' Update date stamp
            DoTouch objFile
        End If
    Next
    
    ' Now drill down into all subfolders recursively
    For Each objSubFolder In objFolder.SubFolders
        FindFiles objSubFolder, datBefore
    Next
End Sub

Sub DoTouch (objFile) 
    ' Get namespace handle to folder and file
    Set objNsFolder = objShell.NameSpace(objFSO.GetParentFolderName(objFile.Path)) 
    Set objNsFile = objNsFolder.ParseName(objFSO.GetFileName(objFile.Path)) 

    ' Update last modified date
    objNsFile.ModifyDate = DateAdd("d", Int(364 * Rnd) + 1, datCutoff)

    Set objNsFile = Nothing 
    Set objNsFolder = Nothing 
End Sub

Open in new window

~bp
0
KreativaAuthor Commented:
Hi Bill,

How should I use this? it does not seems to be DOS ? Wil this also do subdirs? and the files whitin it?

Kid Regards,
Alain.
0
Steve KnightIT ConsultancyCommented:
it is vbscriot - save it in notepad as fixdates.vbs or something . Make sure you change file type from text files to all files when saving so it doesnt add .txt on the end of the name.   then double click it in explorer or strart a cmd.exe prompt and type

cscript //nologo fixdates.vbs

havent looked script over yet but sounds roughly like what I was suggesting.  I did think btw no need to make the dates random, just use current month. Day. Hour etc. And amend the YEAR to 2007...
0
Bill PrewCommented:
As Steve mentioned it's a VBS script, so he covered how to execute it.  Adjust the "C:\" if that's not the drive you want to process.

Yes, it will handle ALL files under the specified folder, including in subfolders.

~bp
0
KreativaAuthor Commented:
Hi Bill,

I just tested it and it works fine, what should I add to have the time also changed?
between 7 and 19

Kind regards,
Alain.
0
Bill PrewCommented:
Can you be more specific on what you mean by "between 7 and 19"?

~bp
0
KreativaAuthor Commented:
The file date is now modified to : 5/02/2007 0:00

the day/month/year is random but the time is always 0:00

could you change the time part (0:00) to something between 7 AM / 7 PM (7 to 19)

Kind regards,
Alain.
0
Bill PrewCommented:
Okay, adjust to the line below, I think that should cover it.

objNsFile.ModifyDate = DateAdd("d", Int(364 * Rnd) + 1, datCutoff) + TimeSerial(Int(12 * Rnd) + 7, Int(60 * Rnd), Int(60 * Rnd))

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KreativaAuthor Commented:
Hey Bill
tnx for the effort!
0
Bill PrewCommented:
Welcome.

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Server Apps

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.