打印出按文件名排序的目录中的文件 [英] Print out files in a directory sorted by FileName
本文介绍了打印出按文件名排序的目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试打印目录中的文档,按文件名升序排列.我有下面的脚本来打印文档,它可以工作,但它的顺序是随机的.有没有办法根据名称对文件"集合进行排序?
I'm trying to print documents in a directory, ordered by file name ascending. I have the script below to print out the documents, which works, but it's in a random order. Is there any way to sort the "files" collection based on name?
'Set the TargetFolder
TargetFolder = "C:\Temp\Hewitt\TestPrintFolder"
Set shellApplication = CreateObject("Shell.Application")
Set folder = shellApplication.Namespace(TargetFolder)
Set files = folder.Items
For Each file In files
file.InvokeVerbEx ("Print")
Next
推荐答案
有很多方法可以获取目录中文件(名称)的列表.一种使用 .NET ArrayList - 像这样:
The are many ways to get an odered list of the file(name)s in a directory. One uses the .NET ArrayList - like this:
Option Explicit
Dim oFS : Set oFS = CreateObject("Scripting.FileSystemObject")
Dim sDir : sDir = "... your folder ..."
Dim oFiles : Set oFiles = CreateObject("System.Collections.ArrayList")
Dim oFile
For Each oFile In oFS.GetFolder(sDir).Files
WScript.Echo oFile.Name
oFiles.Add oFile.Path
Next
WScript.Echo "----------"
oFiles.Sort
Dim sFile
For Each sFile In oFiles
WScript.Echo oFS.GetFile(sFile).Name
Next
如果你不能利用 .Net,你可以
If you can't harness .Net, you could
- 将名称存储在 VBScript 数组中并查找/编写排序子/函数
- 使用断开连接的 ADODB 记录集
- shell 到
dir/o:n
这篇关于打印出按文件名排序的目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文