Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Need to find all the latest files that have been created in a folde i mention.

Hi,

Need to find all the latest files that have been created in a folde i mention.

Say i have a folder called C:\Tools. I Want a script which will search the folder for the created date i mention and list the names in a txt file.

Regards
Sharath
Avatar of Hitesh Manglani
Hitesh Manglani
Flag of India image

Heres a macro
Sub a1()
Dim FSO As Object
Dim FileCreated As String
Dim FileName As String      'Includes the file path
Dim MyDate, FF as Integer
MyDate = #February 12, 1985# 'Set your Date here
 Set FSO =CreateObject("Scripting.FileSystemObject")
Filename = Dir("C:\Tools")
FF=FreeFile
Open "C:\filename.txt" for output as #FF
Do
    if  FSO.GetFile(FileName).DateCreated > MyDate then

           Print  #FF , FileName  
    End if

          Filename = Dir$()

Loop Until Filename<>""
CloseFF
End Sub
ASKER CERTIFIED SOLUTION
Avatar of zoofan
zoofan
Flag of United States of America image

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
Pass the parameters as follows:
filename (space) path to check in dos format(space) date to check for in short date format

filename.vbs folder date

filename.vbs c:\progra~1\microso~1 07/27/2007


zf
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
Any luck in testing this?

zf
Avatar of bsharath

ASKER

Farhankazi.

Is there any thing i need to change in the script.?
No, nothing need to be changed.
Click Start -> Run -> Cmd.exe
         
                                  Search.cmd C:\MyFiles 28/07/2007
Name of the batch file --- ^              ^---Folder name   ^------------- Date
zoofan.

there is a file created in c:\filename but ithas no data in the file.
you did pass the parameters yes? as I ran this about 40 times the last on a folder that has well over 250,000 files and 40,000 subfolders(took a while too)

filename.vbs folder date

filename.vbs c:\progra~1\microso~1 07/27/2007

Leave off the leading zero in the date.

will retest

zf
I have rerun this on 10 different folders all folders that the script is not located in and is working, but did find if you add the leading zero to the date 07 is returns an empty file failing all date tests.

and in its current directory passing a period as the folder to check

filename.vbs c:\ 7/29/2007
filename.vbs . 7/29/2007

and the output file is created in the same directory the script is located in.


zf
Beware, that the script will fail if you run it on an open file as windows cant open the same file twice.

zf
Oh and you need to have files in that folder that were actually created on the date you specify :-)  

optionally you can modify the two

Date2 = FormatDateTime(objFile.DateCreated,2)        

lines to read


Date2 = FormatDateTime(objFile.DateLastModified,2)

And instead of creation date it will check modified date.

zf
Zoofan

 i used this command

findcreateddate.vbs c:\ 07/29/2007
I created a folder and some file now in c drive.But the text file does not update any created dates.

Farhankazi
I used your script too but no data is being updated.
bsharath leave the leading zero off the date

zf
command

findcreateddate.vbs c:\ 7/29/2007

zf
After i changed th date to 7/29/2007 i got it working.Thanks.
What command did you applied?
Great,  I was getting worried as Im still running it to test.


glad it is working,

zf