Link to home
Start Free TrialLog in
Avatar of Kreativa
Kreativa

asked on

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.
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

Older as in creation time or modified time?
Avatar of Bill Prew
Bill Prew

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
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
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.
Here is a VBScript version of "touch" I wrote which will update date / time of a file:

https://www.experts-exchange.com/questions/27441352/DOS-commands-to-change-the-File-Modification-Date-and-File-Creation-Date.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
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
Sounded like it to me Steve...

~bp
Avatar of Kreativa

ASKER

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.
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
Have fun Steve! I can wait another day ;)

Alain.
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
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.
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...
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
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.
Can you be more specific on what you mean by "between 7 and 19"?

~bp
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.
ASKER CERTIFIED 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
Hey Bill
tnx for the effort!
Welcome.

~bp