Fileコレクションの順序は?


てす  2012-08-17 19:42:25  No: 103337

Dim Path 'ディレクトリパス
Dim Fso 'Scripting.FileSystemObject
Dim File 'Fileコレクション

Path = "\\○\○" '該当ディレクトリパス設定

Set Fso = CreateObject("Scripting.FileSystemObject")
Set File = Fso.GetFolder(Path).Files

Fileに格納される順番はどのような順番ですか?
File名順にならんでいるように感じますが、必ずFile名順で格納するようになっているのでしょうか。


魔界の仮面弁士  2012-08-17 23:16:54  No: 103338

当方では、ファイル名順にならない場合も経験しています。

順序に保証されているわけではありませんが、恐らくは、FindFirstFile、FindNextFile APIのファイル検索順序と同じものであろうかと予想しています。

NTFSの場合はファイル名順、FATの場合には作成エントリー順といった感じで。
http://msdn.microsoft.com/en-us/library/aa364428%28VS.85%29.aspx

The order in which this function returns the file names is
dependent on the file system type. With the NTFS file system and CDFS file systems, the names are usually returned in alphabetical order. With FAT file systems, the names are usually returned in the order the files were written to the disk, which may or may not be in alphabetical order. However, as stated previously, these behaviors are not guaranteed.


てす  2012-08-18 02:35:33  No: 103339

VBSにはソートがないと聞きます。
コレクションをファイル名順に並び替えるにはどうすれば良いのでしょうか。


魔界の仮面弁士  2012-08-18 07:31:42  No: 103340

とりあえず、ADODB.Recordset の Sort プロパティで代用されては如何でしょう。

あるいは、JScript の Array.Sort を、wsc 経由や MSScriptControl 経由で
VBScript から利用するといった手もあります。

以下、VBScript のコードではありませんが参考までに。
http://hanatyan.sakura.ne.jp/patio/read.cgi?no=99
http://madia.world.coocan.jp/cgi-bin/VBBBS/wwwlng.cgi?print+201112/11120007.txt


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加