按日期或大小获取目录中的文件 [英] Get Files in Directory by Date or Size

查看:61
本文介绍了按日期或大小获取目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我需要找到目录中比给定的

日期(修改日期或创建日期)更年轻的所有文件。


另外我需要找到一种方法来查找目录中所有文件大小为

a的文件。


提前致谢!!

解决方案

*" Pieter Coucke" < PI ********** @ hotmail.com> scripsit:

我需要找到目录中比给定的日期(修改日期或创建日期)更年轻的所有文件。

我也需要找到一种方法来查找目录中具有给定文件大小的所有文件。




枚举文件:


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


查看''FileInfo ''类及其''长度''属性和

''文件'类及其'Get * Time''方法。


-

Herfried K. Wagner [MVP]

< http://www.mvps.org/dotnet>


亲爱的Pieter

1.在项目中添加表格。

2.添加以下控件:

2.a. DriveListBox(我在其中使用了名为Drive1的
代码)和用于选择路径的DirListBox(dir1)。如果你有一个预定义的路径名,你可以删除这些,或者

想要通过TextBox输入它。

2.b. TextBox(txtFileSize)输入文件大小(

你要搜索)

2.c.用于选择日期的日历控件(Calendar1)

(以可接受的日期格式)。

2.d. TextBox(txtResult)与txtResult.multiline = True

和txtResult.ScrollBars = 2(垂直)用于查看

结果。你也可以免除这个。

2.e. CommandButton(Command1)将填充

txtResult。

3.现在将以下代码粘贴到表单:

''*** *********代码如下:

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&" ; \ *。*")



dFileDate = FileSystem.FileDateTime(sPath&" \"&

sFileName)

lFileSize = FileSystem.FileLen(sPath&" \"&

sFileName)

flag = False

如果dFileDate> Calendar1.Value然后

flag = True

结束如果

如果lFileSize = Val(txtFileSize)则

flag = True

结束如果

如果flag = True那么

txtResult.SelStart = Len(txtResult.Text)

txtResult.SelText = sFileName&空间(10)&

lFileSize&空间(10)& dFileDate& vbCrLf

结束如果

sFileName = Dir()

Loop Until Len(sFileName)= 0

End Sub

''************代码结束

4.运行表格。

这应该有效满足你想做的任何事情

it。

IRFAN。


绝对不要在这个论坛上使用你的实际电子邮件。

我用了一次就得到了大约80个病毒感染的

邮件,据说来自微软。

---- - 原始消息-----


我需要找到目录中比赠品更年轻
的所有文件(修改日期或创建日期)。

此外,我需要找到一种方法来查找
目录中具有给定文件大小的所有文件。

提前致谢!!



非常感谢! :-)我会检查一下:-)


" Irfan Fazli" <一个******* @ discussions.microsoft.com>在消息中写道

news:02 **************************** @ phx.gbl ... < blockquote class =post_quotes>亲爱的Pieter
1.将表格添加到项目中。
2.添加以下控件:
2.a. DriveListBox(我在其代码中使用了名为Drive1)和用于选择路径的DirListBox(dir1)。如果你有一个预定义的路径名,或者想要通过TextBox输入它,你可以删除它们。
2.b. TextBox(txtFileSize)输入文件大小(要搜索的

2.c.用于选择日期的日历控件(Calendar1)
(以可接受的日期格式)。
2.d.带有txtResult.multiline = True
和txtResult.ScrollBars = 2(垂直)的TextBox(txtResult)用于查看
结果。你也可以免除这个。
2.e. CommandButton(Command1)将填充
txtResult。
3.现在将以下代码粘贴到表单:
''************代码如下:
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&" \ *。*")

dFileDate = FileSystem.FileDateTime(sPath&" \"&
sFileName)
lFileSize = FileSystem.FileLen(sPath&" \"&
sFileName)
flag = False
如果dFileDate> Calendar1.Value然后
flag = True
结束如果
如果lFileSize = Val(txtFileSize)那么
flag = True
结束如果
如果flag = True然后
txtResult.SelStart = Len(txtResult.Text)
txtResult.SelText = sFileName&空间(10)&
lFileSize&空间(10)& dFileDate& vbCrLf
结束如果
sFileName = Dir()
循环直到Len(sFileName)= 0
结束子
''********** **代码结束
4.运行表格。
这应该工作并满足你想做的任何事情
它。
IRFAN。

从不在这个论坛上使用你的实际电子邮件。
我曾经使用过一次,我收到大约80封病毒感染的邮件,据说来自微软。

- ---原始消息-----


我需要找到目录中


比给定

date(修改日期或创建日期)。

另外我需要找到一种方法来查找


目录中有

给定的文件大小。

提前致谢!!



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!!

解决方案

* "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>


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!!
.



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!!
.



这篇关于按日期或大小获取目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆