帮助我建立一个更好的kludge [英] Help me build a better kludge

查看:49
本文介绍了帮助我建立一个更好的kludge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要扫描各种网络文件夹并捕获所有文件名和

创建日期。


=========== ======================================= =====

第一次使用典型的驱动器扫描


cFile = Dir(sharedPath)

同时cFile<""

db.Execute(" INSERT INTO Table(FileName,等等)

cFile = Dir

循环


但是在缓慢的公司

网络中迭代25,000个文件时,速度非常慢。


============== ==================================== =====

2nd努力 - shell输出到DOS,运行.bat来捕获文件夹

文本文件中的内容,将文本文件导入Access


nwFolder =" dir" "& sharedPath&""" / t:w"& fileListing&""

Open" C:\ dococPath.bat" For输出为#1

打印#1,nwFolder

关闭#1

v = Shell(" C:\ dococPath.bat",vbHide)

''等待5秒

DoCmd.TransferText acImportFixed,Import Spec,tempTable,文件列表,

错误


这很快,但它只是简单难看。并且Shell异步运行所以

这是一个需要处理的问题(这是一个循环运行所以如果我没有暂停

在Shell声明之后它很快就出错了。


我不认为我对ShellWait很感兴趣。如果

可能,我想要一个更简单的解决方案。


====================== ============================ =====

第三次努力:来自cdma的建议?

谢谢

I need to scan various network folders and capture all the filenames and
create dates.

================================================== =====
1st effort used the typical drive scan

cFile = Dir(sharedPath)
Do While cFile <""
db.Execute("INSERT INTO Table (FileName, blah blah)
cFile = Dir
Loop

But it''s very slow when iterating 25,000 files across a slow corporate
network.

================================================== =====
2nd effort - shell out to DOS, run .bat to capture folder
contents in text file, import text file to Access

nwFolder = "dir """ & sharedPath & """ /t:w " & fileListing & ""
Open "C:\docPath.bat" For Output As #1
Print #1, nwFolder
Close #1
v = Shell("C:\docPath.bat", vbHide)
''wait 5 seconds
DoCmd.TransferText acImportFixed, "Import Spec", "tempTable", fileListing,
False

This is fast, but it''s just plain ugly. And Shell runs asynchronously so
that''s an issue to deal with (this runs in a loop so if I don''t put pauses
after the Shell statement it soon errors out).

I don''t think I''m interested in ShellWait. I want a simpler solution if
possible.

================================================== =====
3rd effort: suggestions from cdma?
Thanks

推荐答案

DFS写道:
DFS wrote:

第三次努力:来自cdma的建议?
3rd effort: suggestions from cdma?



我使用帮助中描述的Application.filesearch方法。这是一个我b $ b proc我从我的一个Oracle应用程序中取出了一个Jet表格在用户的前端用图像文件填充了一个
(表名)是

cImageTableName,常数) - 约表单随机选择

图片,以便在加载启动表单时显示。在Application.filesearch上寻找帮助

主题。我不知道

跟进是多么好,因为它是我最近的一次创作,但没有抱怨所以

远。 strFileEnding是图像类型扩展。你可能想要

来改变它,这样就没有特定文件名的说明。


下面的结构很少基于

A2003的帮助文件信息。 dblocal是指dblocal。在dblocal.execute中使用的是一个David Fenton函数

用于定义一个你不必担心关闭的数据库变量。


Sub sSetUpImageInventorySearchFiles( strFileEnding)

''来自filesearch的访问帮助,foundfiles属性

''在调用函数中处理错误陷阱

Dim i As Integer

Dim intSerial As Integer

Dim strS As String


''将intSerial设置为找到的图像的最后一个数字,然后添加一个


intSerial = Nz(DMax(" serial",cImageTableName),0)


使用Application.FileSearch

.LookIn = cImagesLocation

.SearchSubFolders = False

.FileName =" *" &安培; strFileEnding

如果.Execute()0那么

''MsgBox"有 &安培; .Files.Count& _

"找到的文件。

For i = 1 To StatFiles.Count

''MsgBoxnameFiles(i)

intSerial = intSerial + 1

strS =" insert into" &安培; cImageTableName& " (序列号,

位置)"

strS = strS& vbCrLf& 选择 &安培; intSerial& , &

Chr(34)& .Files(i)& Chr(34)

''Debug.Print strS

dbLocal.Execute strS,dbFailOnError

Next i

否则

''MsgBox"没有找到文件。

结束如果

结束


End Sub


-

Tim http://www.ucs.mun.ca/~tmarshal/

^ o<

/ #)打嗝,打嗝,打嗝? - Quaker Jake

/ ^^小心点,大鸟! - 同上TIM-MAY !! - 我

I use the Application.filesearch method described in help. Here''s a
proc I pulled out of an Oracle app of mine which populates a Jet table
in the user''s front end with image files (the table name is
cImageTableName, a constant) - the "about" form randomly chooses
pictures to display when the splash form is loaded. Look for the help
subject on Application.filesearch. I don''t know how well done the
following is as it''s a recent creation of mine, but no complaints so
far. The strFileEnding is an image type extension. You''d probably want
to alter this so that there''s no specification of a specific file name.

The construction below is laregly based on the help file information for
A2003. The "dblocal" used in dblocal.execute is a David Fenton function
for defining a database variable that you don''t have to worry about closing.

Sub sSetUpImageInventorySearchFiles(strFileEnding)
''from access help for filesearch, foundfiles property
''error trapping handled in calling function
Dim i As Integer
Dim intSerial As Integer
Dim strS As String

''Set intSerial to the last number of an image found and then add one

intSerial = Nz(DMax("serial", cImageTableName), 0)

With Application.FileSearch
.LookIn = cImagesLocation
.SearchSubFolders = False
.FileName = "*" & strFileEnding
If .Execute() 0 Then
''MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
''MsgBox .FoundFiles(i)
intSerial = intSerial + 1
strS = "insert into " & cImageTableName & " (Serial,
Location) "
strS = strS & vbCrLf & "Select " & intSerial & ", " &
Chr(34) & .FoundFiles(i) & Chr(34)
''Debug.Print strS
dbLocal.Execute strS, dbFailOnError
Next i
Else
''MsgBox "There were no files found."
End If
End With

End Sub

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me


你在寻找什么,不使用Shell / Shellwait API'

(非托管代码)将在托管代码环境(VB.Net,C#)

如果退出Access是一个选项。


托管代码有system.diagnostics.process对象它可以以任何你想要的方式同步,异步地运行
。托管代码将所有API捆绑到这个简单的流程对象中。

替代方案是保留Shell / Shellwait API' - 除了代码是不受管理的(不是
)之外,它几乎是相同的。
捆绑在一个漂亮的调试包中,如.Net)所以你必须自己管理代码 - 这是丑陋的部分。


Rich


***通过开发人员指南 http发送://www.developersdex.com ***
What you are looking for that doesn''t use Shell/Shellwait API''s
(unmanaged code) would be in the managed code environment (VB.Net, C#)
if stepping out of Access is an option.

Managed code has the system.diagnostics.process object which can run
synchronously, asynchronously, any way you want. Managed code has
bundled up all the API''s for you into this simple process object. The
alternative is to stay with the Shell/Shellwait API''s - which does
pretty much the same thing except that the code is unmanaged (not
bundled up in a nice neat debugged package like in .Net) so you have to
manage the code yourself - that''s the ugly part.

Rich

*** Sent via Developersdex http://www.developersdex.com ***


谢谢。我忘了提到我还需要文件的最后修改日期。我用
看不到Application.FileSearch对象的可用位置(

..LastModified属性是搜索的一部分,而不是结果)


Tim Marshall写道:
Thanks. I forgot to mention I also need the file''s last modified date. I
don''t see where that''s available with the Application.FileSearch object (the
..LastModified property is part of the search, not the results)

Tim Marshall wrote:

DFS写道:
DFS wrote:

>第三次努力:来自cdma的建议?
>3rd effort: suggestions from cdma?



我使用帮助中描述的Application.filesearch方法。这是一个我b $ b proc我从我的一个Oracle应用程序中取出了一个Jet表格在用户的前端用图像文件填充了一个
(表名)是

cImageTableName,常数) - 约表单随机选择

图片,以便在加载启动表单时显示。在Application.filesearch上寻找帮助

主题。我不知道

跟进是多么好,因为它是我最近的一次创作,但没有抱怨所以

远。 strFileEnding是图像类型扩展。你可能会想要改变这个,所以没有特定文件的说明

名称。

下面的结构是基于A2003的帮助文件信息

。 dblocal是指dblocal。在dblocal.execute中使用的是一个David Fenton

函数,用于定义一个你不需要的数据库变量

担心关闭。

Sub sSetUpImageInventorySearchFiles(strFileEnding)

''来自filesearch的访问帮助,foundfiles属性

''在调用函数中处理错误陷阱


Dim i As Integer

Dim intSerial As Integer

Dim strS As String


''将intSerial设置为最后一个数字找到一个图像,然后添加

一个

intSerial = Nz(DMax(" serial",cImageTableName),0)


使用Application.FileSearch

.LookIn = cImagesLocation

.SearchSubFolders = False

.FileName =" *" &安培; strFileEnding

如果.Execute()0那么

''MsgBox"有 &安培; .Files.Count& _

"找到的文件。

For i = 1 To StatFiles.Count

''MsgBoxnameFiles(i)

intSerial = intSerial + 1

strS =" insert into" &安培; cImageTableName& " (序列号,

位置)"

strS = strS& vbCrLf& 选择 &安培; intSerial& , &

Chr(34)& .Files(i)& Chr(34)

''Debug.Print strS

dbLocal.Execute strS,dbFailOnError

Next i

否则

''MsgBox"没有找到文件。

结束如果


结束时


结束子


I use the Application.filesearch method described in help. Here''s a
proc I pulled out of an Oracle app of mine which populates a Jet table
in the user''s front end with image files (the table name is
cImageTableName, a constant) - the "about" form randomly chooses
pictures to display when the splash form is loaded. Look for the help
subject on Application.filesearch. I don''t know how well done the
following is as it''s a recent creation of mine, but no complaints so
far. The strFileEnding is an image type extension. You''d probably
want to alter this so that there''s no specification of a specific file
name.
The construction below is laregly based on the help file information
for A2003. The "dblocal" used in dblocal.execute is a David Fenton
function for defining a database variable that you don''t have to
worry about closing.
Sub sSetUpImageInventorySearchFiles(strFileEnding)
''from access help for filesearch, foundfiles property
''error trapping handled in calling function
Dim i As Integer
Dim intSerial As Integer
Dim strS As String

''Set intSerial to the last number of an image found and then add
one
intSerial = Nz(DMax("serial", cImageTableName), 0)

With Application.FileSearch
.LookIn = cImagesLocation
.SearchSubFolders = False
.FileName = "*" & strFileEnding
If .Execute() 0 Then
''MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
''MsgBox .FoundFiles(i)
intSerial = intSerial + 1
strS = "insert into " & cImageTableName & " (Serial,
Location) "
strS = strS & vbCrLf & "Select " & intSerial & ", " &
Chr(34) & .FoundFiles(i) & Chr(34)
''Debug.Print strS
dbLocal.Execute strS, dbFailOnError
Next i
Else
''MsgBox "There were no files found."
End If
End With

End Sub



这篇关于帮助我建立一个更好的kludge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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