?
Solved

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

Posted on 2007-07-27
19
Medium Priority
?
283 Views
Last Modified: 2010-03-05
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
0
Comment
Question by:bsharath
  • 10
  • 4
  • 3
  • +1
19 Comments
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 19583921
0
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 19583931
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
0
 
LVL 12

Accepted Solution

by:
zoofan earned 1200 total points
ID: 19584060
Here is a vbscript which will scan files in the specified directory as well as any sub directory's and output the list to
files.txt in the same directory that the script is located in.

to run it  pass the two parameters startfolder(MUST BE DOS CONVENTION 8.3) a space and the date 7/27/2007

==begin script==Option Explicit
      Dim Date1, Date2, objFSO, objStartFolder, objFolder, objFile, colfiles, subfolder
      Dim oFilesys, oFiletxt, sFilename, sPath
      objStartFolder = Wscript.Arguments(0)
      Date1 = Wscript.Arguments(1)
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set oFilesys = CreateObject("Scripting.FileSystemObject")
      Set oFiletxt = oFilesys.CreateTextFile(".\files.txt", True)
      sPath = oFilesys.GetAbsolutePathName(".\files.txt")
      sFilename = oFilesys.GetFileName(sPath)
      Set objFolder = objFSO.GetFolder(objStartFolder)
      Set colfiles = objFolder.Files
                        For Each objFile In colfiles
                           Date2 = FormatDateTime(objFile.DateCreated,2)
                              If Date1 = Date2 Then
                                    oFiletxt.WriteLine(objStartFolder & "\" & objFile.name)
                              End If
                        Next
           
ShowSubFolders objFSO.GetFolder(objStartFolder)
      Sub ShowSubFolders(Folder)
            For Each subfolder In Folder.SubFolders
                  Set objFolder = objFSO.GetFolder(subfolder.Path)
                  Set colfiles = objFolder.Files
                        For Each objFile In colfiles
                           Date2 = FormatDateTime(objFile.DateCreated,2)
                              If Date1 = Date2 Then
                                    oFiletxt.WriteLine(subfolder.Path & "\" & objFile.name)
                              End If
                        Next
                  ShowSubFolders subfolder
            Next
      End Sub
==end script==

If you need help with it let me know.

zf
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 12

Expert Comment

by:zoofan
ID: 19584067
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
0
 
LVL 26

Assisted Solution

by:Farhan Kazi
Farhan Kazi earned 800 total points
ID: 19584141
:: ================
:: READ THIS FIRST
:: ================
:: * Successful will generate 'FileList.txt' file on C: drive root
:: * Copy and paste following script in notepad and save it with any name having .cmd extension.
:: Batch Script Start

@Echo Off
SetLocal EnableDelayedExpansion
IF [%1]==[] Goto :ShowErr
IF [%2]==[] Goto :ShowErr
SET FilesPath=%1
SET FindDate=%2

IF NOT EXIST "%FilesPath%" Echo '%FilesPath%' Invalid path. && Goto :EndScript
IF EXIST C:\FileList.txt DEL /F /Q C:\FileList.txt

FOR /R "%FilesPath%" %%F IN (*.*) Do (
    SET FDate=%%~tF
    SET MM=!FDate:~,2!
    SET DD=!FDate:~3,2!
    SET YYYY=!FDate:~6,4!
    SET FDate=!DD!/!MM!/!YYYY!
      IF       "!FindDate!"=="!FDate!" Echo %%~nF%%~xF && Echo %%~nF%%~xF>>C:\FileList.txt
)
Goto EndScript
:ShowErr
Echo.
Echo Missing/Invalid parameters.
Echo Syntax:
Echo       BatchFileName.cmd ^<FolderPath^> ^<DD/MM/YYYY^>
Echo Example:
Echo       Search.cmd C:\MyFiles 28/07/2007
:EndScript
ENDLOCAL
:: Batch Script End
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19585464
Any luck in testing this?

zf
0
 
LVL 11

Author Comment

by:bsharath
ID: 19586078
Farhankazi.

Is there any thing i need to change in the script.?
0
 
LVL 26

Expert Comment

by:Farhan Kazi
ID: 19586236
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
0
 
LVL 11

Author Comment

by:bsharath
ID: 19587603
zoofan.

there is a file created in c:\filename but ithas no data in the file.
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19587618
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
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19587622
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
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19587624
Beware, that the script will fail if you run it on an open file as windows cant open the same file twice.

zf
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19587634
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
0
 
LVL 11

Author Comment

by:bsharath
ID: 19587641
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.
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19587644
bsharath leave the leading zero off the date

zf
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19587646
command

findcreateddate.vbs c:\ 7/29/2007

zf
0
 
LVL 11

Author Comment

by:bsharath
ID: 19587647
After i changed th date to 7/29/2007 i got it working.Thanks.
0
 
LVL 26

Expert Comment

by:Farhan Kazi
ID: 19587649
What command did you applied?
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19587652
Great,  I was getting worried as Im still running it to test.


glad it is working,

zf
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some time ago I faced the need to use a uniform folder structure that spanned across numerous sites of an enterprise to be used as a common repository for the Software packages of the Configuration Manager 2007 infrastructure. Because the procedu…
Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip is around source server preparation. No migration is an easy migration, there is a…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question