473,473 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Get Files in Directory by Date or Size

Hi,

I need to find all the files in a directory which are younger than a given
date (modification date or creation date).

Also I need to find a way to find all files in a directory which are having
a given file size.

Thanks in advance!!
Nov 20 '05 #1
10 6662
* "Pieter Coucke" <pi**********@hotmail.com> scripsit:
I need to find all the files in a directory which are younger than a given
date (modification date or creation date).

Also I need to find a way to find all files in a directory which are having
a given file size.


Enumerating files:

<http://www.mvps.org/dotnet/dotnet/samples/filesystem/downloads/RecursiveFileScan.zip>

Have a look at the 'FileInfo' class and its 'Length' property and the
'File' class and its 'Get*Time' methods.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Dear Pieter
1. Add a form to a project.
2. Add the following controls:
2.a. DriveListBox (named Drive1 that I have used in he
code) and DirListBox (dir1) for selecting the path. You
may remove these if you have a predefined pathname or
want to have it inputted thru TextBox.
2.b. TextBox (txtFileSize) to input the File Size (which
you want to search)
2.c. Calendar Control (Calendar1) for selecting the date
(in the acceptable date format).
2.d. TextBox (txtResult) with txtResult.multiline=True
and txtResult.ScrollBars =2 (Vertical) for viewing the
result. You can dispense with this also.
2.e. CommandButton (Command1) that will populate the
txtResult.
3. Now Paste the following code to the form:
'************Code follows:
Private Sub Command1_Click()
PopulateGrid Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
Dir1.Refresh
End Sub

Public Sub PopulateGrid(sPath As String)
Dim sFileName As String
Dim dFileDate As Date
Dim lFileSize As Long
Dim flag As Boolean
txtResult.Text = ""
sFileName = Dir(sPath & "\*.*")
Do
dFileDate = FileSystem.FileDateTime(sPath & "\" &
sFileName)
lFileSize = FileSystem.FileLen(sPath & "\" &
sFileName)
flag = False
If dFileDate > Calendar1.Value Then
flag = True
End If
If lFileSize = Val(txtFileSize) Then
flag = True
End If
If flag = True Then
txtResult.SelStart = Len(txtResult.Text)
txtResult.SelText = sFileName & Space(10) &
lFileSize & Space(10) & dFileDate & vbCrLf
End If
sFileName = Dir()
Loop Until Len(sFileName) = 0
End Sub
'************Code ends
4. Run the Form.
This should work and satisfy whatever you want to do with
it.
IRFAN.

NEVER USE YOUR ACTUAL E-MAILID on this forum.
I used it once and am getting about 80 virus-infected
mails, supposedly from Microsoft.
-----Original Message-----
Hi,

I need to find all the files in a directory which are younger than a givendate (modification date or creation date).

Also I need to find a way to find all files in a directory which are havinga given file size.

Thanks in advance!!
.

Nov 20 '05 #3
thanks a lot! :-) I'll check it out :-)

"Irfan Fazli" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Dear Pieter
1. Add a form to a project.
2. Add the following controls:
2.a. DriveListBox (named Drive1 that I have used in he
code) and DirListBox (dir1) for selecting the path. You
may remove these if you have a predefined pathname or
want to have it inputted thru TextBox.
2.b. TextBox (txtFileSize) to input the File Size (which
you want to search)
2.c. Calendar Control (Calendar1) for selecting the date
(in the acceptable date format).
2.d. TextBox (txtResult) with txtResult.multiline=True
and txtResult.ScrollBars =2 (Vertical) for viewing the
result. You can dispense with this also.
2.e. CommandButton (Command1) that will populate the
txtResult.
3. Now Paste the following code to the form:
'************Code follows:
Private Sub Command1_Click()
PopulateGrid Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
Dir1.Refresh
End Sub

Public Sub PopulateGrid(sPath As String)
Dim sFileName As String
Dim dFileDate As Date
Dim lFileSize As Long
Dim flag As Boolean
txtResult.Text = ""
sFileName = Dir(sPath & "\*.*")
Do
dFileDate = FileSystem.FileDateTime(sPath & "\" &
sFileName)
lFileSize = FileSystem.FileLen(sPath & "\" &
sFileName)
flag = False
If dFileDate > Calendar1.Value Then
flag = True
End If
If lFileSize = Val(txtFileSize) Then
flag = True
End If
If flag = True Then
txtResult.SelStart = Len(txtResult.Text)
txtResult.SelText = sFileName & Space(10) &
lFileSize & Space(10) & dFileDate & vbCrLf
End If
sFileName = Dir()
Loop Until Len(sFileName) = 0
End Sub
'************Code ends
4. Run the Form.
This should work and satisfy whatever you want to do with
it.
IRFAN.

NEVER USE YOUR ACTUAL E-MAILID on this forum.
I used it once and am getting about 80 virus-infected
mails, supposedly from Microsoft.
-----Original Message-----
Hi,

I need to find all the files in a directory which are

younger than a given
date (modification date or creation date).

Also I need to find a way to find all files in a

directory which are having
a given file size.

Thanks in advance!!
.

Nov 20 '05 #4
Hi!

Unfortunately none of the 2 answers where whta I needed :-(

What I need is a way to get the name of all the files in a directory, whcih
are odler than an given date. I don't need to visualize it, but just have to
put the names in an array.

Anybody any idea?

"Pieter Coucke" <pi**********@hotmail.com> wrote in message
news:3f**********************@reader0.news.skynet. be...
Hi,

I need to find all the files in a directory which are younger than a given
date (modification date or creation date).

Also I need to find a way to find all files in a directory which are having a given file size.

Thanks in advance!!

Nov 20 '05 #5
Cor
Hi Pieter,

Herfried did give you this information.
Have a look at the 'FileInfo' class and its 'Length' property and the
File' class and its 'Get*Time' methods.


With that it would not be that dificult I thought.
Why the File I don't see because all you ask is in the FileInfo class.

What is the problem.

Cor
Nov 20 '05 #6
On Tue, 2 Dec 2003 14:57:21 +0100, DraguVaso wrote:
What I need is a way to get the name of all the files in a directory, whcih
are odler than an given date. I don't need to visualize it, but just have to


Perhaps this will help you:

Private Sub Button1_Click(...) Handles Button1.Click
Dim aFiles() As String
Dim alFiltered As New ArrayList
Dim dCompareDate As Date = #10/31/2003#

aFiles = Directory.GetFiles("c:\dirnamehere")

For x As Integer = 0 To aFiles.Length - 1
If File.GetLastWriteTime(aFiles(x)) < dCompareDate Then
alFiltered.Add(aFiles(x))
End If
Next

For Each s As String In alFiltered
Debug.WriteLine(s)
Next
End Sub
--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #7
Thansk guys!

It's a perfect solution for the problem I had, I was jsut looking if there
was maybe a 'nicer' way:
liek this it first takes all the files, and than picks only the files with
the correct date. What I was looking for was something that took only the
'good' files without firts taking them all. But I guess that won't be
possible.

Thanks a lot for the help!

"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:ae*****************************@40tude.net...
On Tue, 2 Dec 2003 14:57:21 +0100, DraguVaso wrote:
What I need is a way to get the name of all the files in a directory, whcih are odler than an given date. I don't need to visualize it, but just
have to
Perhaps this will help you:

Private Sub Button1_Click(...) Handles Button1.Click
Dim aFiles() As String
Dim alFiltered As New ArrayList
Dim dCompareDate As Date = #10/31/2003#

aFiles = Directory.GetFiles("c:\dirnamehere")

For x As Integer = 0 To aFiles.Length - 1
If File.GetLastWriteTime(aFiles(x)) < dCompareDate Then
alFiltered.Add(aFiles(x))
End If
Next

For Each s As String In alFiltered
Debug.WriteLine(s)
Next
End Sub
--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 20 '05 #8
* "DraguVaso" <pi**********@hotmail.com> scripsit:
Unfortunately none of the 2 answers where whta I needed :-(


I am sure you will be able to solve the problem _yourself_ when
"wasting" some time to understand the hints I gave.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
I evaluated your answer, and I understood it, but like I explained 5 minutes
ago it wasn't exactly what I needed. But still thanks for the help! I guess
the File and FileInfo-class are the best solutions for what I was looking
for! So thank you very much!

*kiss* hehe ;-)

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bq*************@ID-208219.news.uni-berlin.de...
* "DraguVaso" <pi**********@hotmail.com> scripsit:
Unfortunately none of the 2 answers where whta I needed :-(


I am sure you will be able to solve the problem _yourself_ when
"wasting" some time to understand the hints I gave.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #10
* "DraguVaso" <pi**********@hotmail.com> scripsit:
*kiss* hehe ;-)


Huh...

;-)

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: TokiDoki | last post by:
Hello there, I have been programming python for a little while, now. But as I am beginning to do more complex stuff, I am running into small organization problems. It is possible that what I...
2
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet...
10
by: Martin Ho | last post by:
I am running into one really big problem. I wrote a script in vb.net to make a copy of folders and subfolder to another destination: - in 'from.txt' I specify which folders to copy - in...
4
by: feng | last post by:
Hi, I need to implement a function, GetAllFiles, of a web service that once called, returns all the files in a folder to the caller. My question is: what is the best way to implement this...
3
by: jaeden99 | last post by:
I was wandering if nyone has a script to move files older than x days old? i've seen several to delete, but I don't want to delete. I would like to create a backup of the files first verify with...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
5
by: Albert-jan Roskam | last post by:
Hi, I wrote the program below to merge all xls files in a given directory into one multisheet xls file. It uses xlwt and xlrd. The xls files I use for input are generated by Spss. When I open and...
0
by: Albert-jan Roskam | last post by:
Hi John, Thanks! Using a higher xlrd version did the trick! Regarding your other remarks: -yep, input files with multiple sheets don't work yet. I kinda repressed that ;-) Spss outputs only...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.