保存一个前面带有一个字母的新文件

发布于 2024-11-04 17:00:54 字数 702 浏览 0 评论 0原文

请查找代码:

问题是该文件夹有一个很大的编号。文件数

=====================================================================================
Dim fso, objFolder, obFileList, folderpath,counter

folderpath = "G:\Everyone\Model Office Testing Documents\HP QC\QTP\PSISAutomation\Logs"

Set fso = CreateObject("Scripting.FileSystemObject")

Set objFolder = fso.GetFolder(folderpath)

Set objFileList = objFolder.Files


For Each File In objFileList
    msgbox("5")
     If InStr(1,File.Name,"DE_For_Pol_Print_APPA_7A_Copy_") = 1 Then        
        counter=counter+1
     End If   
Next 

counter=counter+1
msgbox("new file will be saved as: " &"DE_For_Pol_Print_APPA_7A_Copy_"& Chr(64 + Counter))

Please find the code:

Problem is the folder has a large no. of files

=====================================================================================
Dim fso, objFolder, obFileList, folderpath,counter

folderpath = "G:\Everyone\Model Office Testing Documents\HP QC\QTP\PSISAutomation\Logs"

Set fso = CreateObject("Scripting.FileSystemObject")

Set objFolder = fso.GetFolder(folderpath)

Set objFileList = objFolder.Files


For Each File In objFileList
    msgbox("5")
     If InStr(1,File.Name,"DE_For_Pol_Print_APPA_7A_Copy_") = 1 Then        
        counter=counter+1
     End If   
Next 

counter=counter+1
msgbox("new file will be saved as: " &"DE_For_Pol_Print_APPA_7A_Copy_"& Chr(64 + Counter))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一人独醉 2024-11-11 17:00:54

不要使用 FSO,而应使用 WMI,将文件名放入 SELECT 语句中,例如:"DE_For_Pol_Print_APPA_7A_Copy_%"。这应该返回一个仅包含具有所请求文件名的文件的集合(比总集合更快)。

文件集合没有 count 属性,但您可以使用:

For Each file in fileCollection
    counter = counter + 1
Next

这不会访问内部文件对象,并且应该运行得相当快。

第二种甚至更快(但在我看来更丑陋)的技术是使用 windowshell 对象中的命令提示符并将目录返回到输出。输出只是一个字符串。现在,计算所需字符串 (DE_For_Pol_Print_APPA_7A_Copy_) 上的匹配数量,这就是您的计数器。

确切的代码留空作为海报的练习。

Do not use the FSO, but make use of the WMI where you put the filename in the SELECT statement, like: "DE_For_Pol_Print_APPA_7A_Copy_%". This should return a collection with only files with the requested filename (faster than a total collection).

There is no count property for file collections, but you can use:

For Each file in fileCollection
    counter = counter + 1
Next

This will not access the internal file object and should run reasonably fast.

A second and even faster (but uglier imo) technique is to use the command prompt from a windowshell object and return the dir to the output. The output is just a string. Now, count the amount of matches on your desired string (DE_For_Pol_Print_APPA_7A_Copy_) and that is your counter.

The exact code is left blank as an excercise for the poster.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文