(for Internet Explorer)
Function  NewDiffFilePaths( in_PathArray as array of string,
    in_RemovePathArray as array of string ) as dictionary of PathDictionaryClass
    Set diff_paths = NewDiffFilePaths( Array( _
        "C:\Attached", "C:\Base" ), Empty )

    For Each  step_path  In  diff_paths.Keys
        Set files = diff_paths( step_path )
        If files( 0 ) Is Nothing Then
            echo  "A>"
        Else
            echo  "A>"+ GetFullPath( step_path, files( 0 ).BasePath )
        End If
        If files( 1 ) Is Nothing Then
            echo  "B>"
        Else
            echo  "B>"+ GetFullPath( step_path, files( 1 ).BasePath )
        End If
    Next
複数のフォルダーを比較するための、ファイルの相対パスをキーとした辞書を生成します。
【引数】
in_PathArray
in_RemovePathArray
フォルダーのパス(フル パス、または、相対パス)の配列
除外するファイル名のパターンの配列、または、Empty
返り値
辞書、キーは相対パス、アイテムは空の
サンプル
PathDictionaryClass
in_RemovePathArray 引数は、
の in_RemovePathArray 引数と
同じ意味です。
上記サンプルの出力例:
A>C:\Attached\Add.txt
B>
A>C:\Attached\Both.txt
B>C:\Base\Both.txt
A>
B>C:\Base\Delete.txt
→ vbslib.vbs
ソース
空のフォルダーは返り値のキーに含まれません。
関連
Function  Dic_addFilePaths_fromPathDirectory( in_out_Dictionary as Dictionary or Empty,
    in_SetIndex as integer,  in_MaxIndex as integer,  in_BasePath as string,
    in_PathDictionary as PathDictionaryClass,  in_Item as Object )
ファイルの相対パスをキーとした辞書の配列に、PathDictionary型の辞書にあるアイテムを追加します。
【引数】
in_out_Dictionary
in_SetIndex
辞書、キーは相対パス、Empty 可能、アイテムは
in_Item を設定する in_out_Dictionary 引数のアイテムの配列の番号
in_MaxIndex
アイテムの配列の最大番号
関連
テスト
→ T_Wildcard.vbs
ソース
T_Dic_addFilePaths
in_PathDictionary
in_PathDictionary 辞書のキーを相対パスにするときの基準フォルダーのパス
in_BasePath
Empty、または、in_PathDictionary のアイテムと比較するキー オブジェクト
返り値
in_out_Dictionary、または、生成した辞書
in_Item
抽出したキーとアイテムは、in_out_Dictionary 引数に指定した辞書のアイテム(ArrayClass 型の配列)の
配列要素に格納されます。 抽出したキーは、in_BasePath 引数に指定したパスを基準とした相対パスに
変換後、抽出したアイテムを追加する先の配列を特定するための辞書のキーとして使われます。
in_SetIndex 引数に指定した値が配列番号となる配列要素に、in_PathDictionary 引数の辞書のアイテム
が格納されます。
For Each  file_path  In  in_PathDictionary.FullPaths
    If in_PathDictionary( file_path )  is  in_Item Then
        file_step_path = GetStepPath( file_path, in_BasePath )
        Set in_out_Dictionary( file_step_path )( in_SetIndex ) = in_Item
Dic_addFilePaths_fromPathDirectory 関数の処理内容は、おおよそ下記の擬似コードのようになります。
in_out_Dictionary 引数に Empty を指定すると、辞書を新規作成され、その辞書が返り値になります。
in_out_Dictionary 引数に辞書を指定すると、その辞書に要素が追加され、その辞書が返り値になります。
in_out_Dictionary 引数に指定した辞書のアイテムの配列の全要素は、Nothing で初期化されます。
・in_PathDictionary 引数に指定した PathDictionaryClass 型の辞書のアイテムが in_Item 引数に
 指定したオブジェクトになっている(in_Item が Empty ではないとき)
in_PathDictionary 引数から、以下の条件に合うキー(パス)とアイテム(オブジェクト)のセットを抽出します。
in_out_Dictionary
引数の辞書
配列
ファイルの
相対パス
配列要素
in_SetIndex 引数
in_PathDictionary 引数の
辞書のアイテム
in_PathDictionary
引数の辞書
(PathDictionaryClass 型)
ファイルのパス
in_Item 引数と同じアイテム
複数のフォルダーを比較するときなど、同じ相対パスのファイルに対して何らかの処理をするときに使い
ます。
Dic_addFilePaths_fromPathDirectory 関数を、それぞれのフォルダーに対して呼び出し、できた
in_out_Dictionary 引数の辞書を使って、それぞれのフォルダーにある、同じ相対パスのファイル
に対する処理ができるようになります。
Set dic_A = new PathDictionaryClass : Set dic_A( "C:\FolderA" ) = obj_A
Set dic_B = new PathDictionaryClass : Set dic_B( "C:\FolderB" ) = obj_B

Set dic_A_B = CreateObject( "Scripting.Dictionary" )
Dic_addFilePaths_fromPathDirectory  dic_A_B, 0, 1, "C:\FolderA", dic_A, obj_A
Dic_addFilePaths_fromPathDirectory  dic_A_B, 1, 1, "C:\FolderB", dic_B, obj_B

For Each  step_path  In  dic_A_B.Keys
    Set files = dic_A_B( step_path )
    If not files( 0 ) Is Nothing  and  not files( 1 ) Is Nothing Then
        If not IsSameBinaryFile( _
               GetFullPath( step_path, obj_A.BasePath ), _
               GetFullPath( step_path, obj_B.BasePath , Empty ) Then
           ....
サンプル
in_BasePath 引数に指定したフォルダーの中のファイルに対応する、in_PathDictionary 引数の辞書の
アイテムに、in_Item 引数のオブジェクト以外が入っている可能性があります。
また、in_BasePath 引数に指定したフォルダーの外のファイルでも、in_PathDictionary 引数の辞書の
アイテムに、in_Item 引数のオブジェクトが抽出される可能性があります。
Dic_addFilePaths_fromPathDirectory
→ vbslib.vbs
Function  Dic_addFilePaths_fromOtherPathDirectory( in_out_Dictionary as Dictionary or Empty,
    in_SetIndex as integer,  in_MaxIndex as integer,
    in_BasePath as string,  in_NewItem as Object,
    in_OtherBasePath as string,  in_OtherPathDictionary as PathDictionaryClass,  in_OtherItem as Object )
ファイルの相対パスをキーとした辞書の配列に、PathDictionary型の辞書にあるアイテムを追加します。
【引数】
in_out_Dictionary
in_SetIndex
辞書、キーは相対パス、Empty 可能、アイテムは
in_Item を設定する in_out_Dictionary 引数のアイテムの配列の番号
in_MaxIndex
アイテムの配列の最大番号
in_OtherPathDictionary
in_out_Dictionary 辞書のキーを相対パスにするときの基準フォルダーのパス
in_BasePath
Empty、または、in_OtherPathDictionary のアイテムと比較するキー オブジェクト
返り値
in_out_Dictionary、または、生成した辞書
in_OtherItem
in_NewItem
in_OtherBasePath
in_out_Dictionary 辞書に追加するオブジェクト
in_OtherPathDictionary 辞書のキーを相対パスにするときの基準フォルダーのパス
in_BasePath 引数の値を基準のパスとした、in_OtherPathDictionary のキー(と in_OtherBasePath からできる)
相対パスに、ファイルまたはフォルダーがあれば、その相対パスを in_out_Dictionary 辞書のキーとし、in_NewItem
を in_out_Dictionary 辞書のアイテムとなるように登録します。
参考
→ SyncFilesMenuLib.vbs
For Each  a_pair  In  GetInputOutputFilePaths( InputPath, Empty, "Temporary_*.txt" )

    copy_ren  a_pair.InputPath,  a_pair.OutputPath  '// メインとなる変換処理に相当

    If a_pair.IsOutputPathTemporary Then _
        move_ren  a_pair.OutputPath, a_pair.InputPath
Next
Function  GetInputOutputFilePaths( InputPath as string or PathDictionaryClass,  OutputPath as string,
    TemporaryBaseName as string ) as array of InputOutputFilePathClass
ファイルを変換するときの、入力ファイルと出力ファイルのパスの配列を返します。
【引数】
InputPath
OutputPath
入力ファイルのパス、または、
出力ファイルのパス、Empty = 入力ファイルに上書き
TemporaryBaseName
OutputPath = Empty のときに使う、一時ファイルの名前
テスト
サンプル
ソース
入力ファイルと出力ファイルのパスの配列
返り値
For Each  a_pair  In  GetInputOutputFilePaths( "a.txt", "b.txt", "Temporary_*.txt" )
→ vbslib.vbs
→ T_Wildcard.vbs
T_GetInputOutputFilePaths
サンプル
For Each  a_pair  In  GetInputOutputFilePaths( "a.txt", Empty, "Temporary_*.txt" )
For Each  a_pair  In  GetInputOutputFilePaths( "FolderA", "FolderB", "Temporary_*.txt" )
Set paths = new PathDictionaryClass
Set paths( "Files\*.c" ) = Nothing
Set paths( "Files\*.h" ) = Nothing
For Each  a_pair  In  GetInputOutputFilePaths( paths, Empty, "Temporary_*.txt" )
OutputPath = Empty が指定されると、返り値の配列要素のメンバー IsOutputPathTemporary は True になり、
返り値の配列要素のメンバー OutputPath は、TemporaryBaseName 引数に基づいた一時ファイルのパスに
なります。 これは、下記のサンプルのように出力ファイルを入力ファイルに上書きするときに使います。
InputPath 引数と OutputPath 引数が同じパスのときも、OutputPath = Empty が指定されたときと同じ返り値
になります。
引数のバリエーション
入力ファイルに上書きすることに対応したコード
関連
InputPath に PathDictionaryClass のオブジェクトを指定できることが特徴です。
ソース
→ vbslib.vbs
の返り値(配列)の要素。
.InputPath
入力ファイルのパス
.OutputPath
.IsOutputPathTemporary
出力ファイルのパス
OutputPath メンバーは、入力ファイルに上書きする前の一時ファイルのパスかどうか
Function  ArrayFromWildcard2( WildcardPath as string ) as PathDictionaryClass of Nothing
ワイルドカードを展開します。 サブ フォルダーも検索します。
【引数】
WildcardPath
フォルダーパス。 ワイルドカードも可。
返り値
of Nothing
テスト
ソース
→ vbslib.vbs
→ T_Wildcard.vbs
T_ArrayFromWildcard2
との違いは、返り値の BasePath プロパティが、WildcardPath 引数に指定した
フォルダーになることです。 ArrayFromWildcard では、カレント・フォルダーが BasePath のプロパ
ティになります。 ワイルドカードがあると、ファイル名でフィルターします。
Set paths = ArrayFromWildcard2( "Folder" )
Assert  paths.BasePath = GetFullPath( "Folder", Empty )
Assert  IsSameArray( paths.FilePaths, Array( "A.txt", "B.ini", "Sub\A.txt" ) )
サンプル
サンプル
Set paths = ArrayFromWildcard2( "Folder\*.txt" )
Assert  paths.BasePath = GetFullPath( "Folder", Empty )
Assert  IsSameArray( paths.FilePaths, Array( "A.txt", "Sub\A.txt" ) )
ワイルドカードがないときは、ファイル または フォルダーのパスとして展開します。
指定したパスが指す場所にファイルかフォルダーのどちらがあるかによって変わります。
どちらも存在しないときは、エラーになります。
ワイルドカードがあるときは、ファイル名でフィルターします。
一般に、相対パスのベースとなるフォルダーのパスを WildcardPath 引数に指定します。
BasePath プロパティを明示的に指定したいときは、
を生成してください。
Function  IsWildcard( path as string ) as boolean
文字列の中にワイルドカードを含むかどうかを返します。
【引数】
path
返り値
調べる文字列
path の中にワイルドカードを含むかどうか
(src)
関連
Function  IsMatchedWithWildcard( Path, WildCard ) as boolean
ワイルドカードにマッチするかどうかを返します。
【引数】
ワイルドカード
WildCard
検査する文字列
Path
WildCard で指定できるワイルドカードは、先頭に * だけです。
WildCard に * が無い文字列も指定できます。
(src)
サンプル
Assert  IsMatchedWithWildcard( "a.bmp", "*.bmp" ) = True
Assert  IsMatchedWithWildcard( "a.bmp", "*.jpg" ) = False
Path がワイルドカードにマッチしたかどうか
返り値
関連
→ T_Wildcard.vbs
テスト
Sub  RemoveWildcardMatchedArrayItems( in_out_PathArray as array of string, WildCard as string )
ワイルドカードにマッチしたパスを配列から除きます。
【引数】
ワイルドカードを含むファイルまたはフォルダの名前
WildCard
(入出力) パスが入った文字列の配列
in_out_PathArray
WildCard で指定できるワイルドカードは、先頭に * だけです。
WildCard に * が無い文字列も指定できます。
(src)
サンプル
arr = Array( "a.jpg", "b.bmp", "c.jpg" )
RemoveWildcardMatchedArrayItems  arr, "*.jpg"
Assert  IsSameArray( arr, Array( "b.bmp" ) )
Sub  RemoveWildcard( WildCard as string, fnames as array of string )
(src)
廃止予定です
代わり
→ T_Wildcard.vbs # [T_ReplaceFileNameWildcard]
Assert  ReplaceFileNameWildcard( "Fo\File.txt", "Fo\*.txt", "Fo\*.ini" ) = "Fo\File.ini"
Function  ReplaceFileNameWildcard( Path as string, FromStr as string, ToStr as string )
ワイルドカードを使って、ファイルパスを変更します。
【引数】
Path
FromStr
ファイルパス(ワイルドカードは使えません)
変更前の文字列。ワイルドカード可能。
ToStr
変更後の文字列。ワイルドカード可能。 "" 可能。
ファイル:
vbslib.lib
サンプル
変更後のファイルパス。 Empty=Path が FromStr にマッチしなかった
返り値
(src)
テスト
Path に親フォルダー名が含まれるときは、FromStr, ToStr にも親フォルダー名を含めてください。
s= ReplaceFileNameWildcard( Fo\File.txt", "Fo\*.txt", "Fo\*.xml"  '// OK
s= ReplaceFileNameWildcard( Fo\File.txt", "*.txt", "*.xml"        '// NG
Path が、FromStr にマッチしなかったときは、Empty が返ります。
関連
ワイルドカードにマッチするかどうか
count = GetReadOnlyList( "C:\Folder", read_onlys, Empty )
For Each step_path  In read_onlys.Keys
    is_read_only = read_onlys( step_path )  '// step_path="FileA.txt", ...
Next
Function  GetReadOnlyList( TargetPath as string,
    out_ReadOnlyDictionary as dictionary of boolean,  Opt as Empty ) as integer
フォルダーにあるすべてのファイルの読み取り属性と、読み取り属性がオンの数を取得します。
【引数】
TargetPath
out_ReadOnlyDictionary
調べるフォルダー、またはファイルのパス
(出力) 読み取り専用かどうかの辞書、キーは相対パス、Empty可
Opt
Empty
テスト
サンプル
ソース
読み取り属性がオンであるファイルの数
返り値
→ T_File.vbs
T_GetReadOnlyList
→ ToolsLib.vbs
フォルダー自体の 読み取り属性は取得できません。
out_ReadOnlyDictionary 引数には、読み取り属性がオンのファイルとオフのファイルの両方が含まれます。
サンプル
count = GetReadOnlyList( "C:\Folder\FileA.txt", read_onlys, Empty )
For Each step_path  In read_onlys.Keys
    is_read_only = read_onlys( step_path )  '// step_path="."
Next
TargetPath 引数にフォルダーを指定した場合
TargetPath 引数にファイルを指定した場合
関連
読み取り属性がオンであるファイルがないことをチェックする
サンプル
Assert  GetReadOnlyList( "C:\Folder\FileA.txt", Empty, Empty ) = 0
read_onlys.Keys から、読み取り属性がオンであるファイルのパスが分かります。
サブ・フォルダー・オブジェクトを高速に辞書に列挙します。 サブフォルダのサブフォルダも列挙します。
【引数】
in_EmptyOption
in_FolderPath
Empty を指定してください
調べるフォルダのパス。 このフォルダの中から列挙します
Sub  EnumFolderObjectDic( in_FolderPath as string,  in_EmptyOption as Empty,
    out_Folders as dictinoary of Folder )
(出力) サブフォルダを含む Folder オブジェクトの辞書
out_Folders
out_Folders には、in_FolderPath の Folder オブジェクトと、in_FolderPath のサブフォルダーの Folder
オブジェクトの両方が含まれます。 in_FolderPath に相当するキーの値は "." です。
out_Folders は辞書型です。 キーは、フォルダーへの相対パスです。 その基準フォルダーは、
in_FolderPath です。 アイテムは、Folder オブジェクトです。
    EnumFolderObjectDic  "C:\FolderA",  Empty,  folders1  '// Set "folders1"
    EnumFolderObjectDic  "C:\FolderB",  Empty,  folders2  '// Set "folders2"
    For Each  step_path  In  folders1.Keys
        If not folders2.Exists( step_path ) Then
            mkdir  "C:\FolderB\"+ step_path
            For Each  file  In  folders1.Item( step_path ).Files
                copy  "C:\FolderA\"+ step_path + file.Name,  "C:\FolderB\"+ step_path
            Next
        End If
    Next
サンプル
EnumFolderObjectDic
EnumFolderObjectDic
関連
出力例
"."
"fe"
"fo1"
"fo1\fo1"
"fo1\fo11.ex"
"fo1\t1"
"fo2"
テスト
→ T_Wildcard.vbs
T_EnumFolderObjectDic
→ vbslib.vbs
ソース
(src)
フォルダの中のファイル・オブジェクトを高速に辞書に列挙します。
【引数】
out_Files
FolderOrPath
(出力) ファイルのオブジェクトの辞書
調べるフォルダのパス。 または、Folder オブジェクト(高速)
Sub  EnumFileObjectDic( FolderOrPath as string or Folder, out_Files as dictinoary of File
out_Files は辞書型です。 キーは、ファイル名です。 アイテムは、File オブジェクトです。
サブ・フォルダーにあるファイルは列挙しません。
  Dim  files1, files2, file_name

  EnumFileObjectDic  "C:\FolderA", files1  '// [out] files1
  EnumFileObjectDic  "C:\FolderB", files2  '// [out] files2
  For Each file_name  In files1.Keys
    If not files2.Exists( file_name ) Then
      copy  "C:\FolderA\"+ file_name,  "C:\FolderB"
    End If
  Next
サンプル
EnumFileObjectDic
EnumFileObjectDic
関連
Sub  EnumFolderObject( FolderPath as string, out_Folders as array of Folder )
サブ フォルダーのオブジェクトを高速に列挙します。 サブ フォルダーのサブ フォルダーも列挙します。
【引数】
out_Folders
FolderPath
(出力) サブフォルダのオブジェクトの配列
調べるフォルダのパス。 このフォルダの中から列挙します
(src)
  Set fname_key = new StrMatchKey
  fname_key.Keyword = LCase( "*.txt" )

  EnumFolderObject  "C:\FolderA", folders  '// Set "folders"
  For Each fo  In folders  '// fo as Folder
    For Each fi  In fo.Files '// fo as File
      If fname_key.IsMatch( fi.Name ) Then
        echo  fi.DateLastModified
      End If
    Next
  Next
関連
out_Folders には、FolderPath の Folder オブジェクトと、FolderPath のサブ フォルダーの Folder
オブジェクトの両方が含まれます。
サンプル
EnumFolderObject
サブ・フォルダーを列挙しない場合
性能
サンプル
    EnumFolderObject  "C:\FolderA", folders  '// Set "folders"
    For Each  folder  In  folders  '// folder as Folder Object
        For Each  file  In  folder.Files '// file as File Object
            echo  file.Path
        Next
    Next
EnumFolderObject
Sub  GetSubFolders( folders as array of string, path as string )
サブ フォルダーのパスを列挙します。 サブ フォルダーのサブ フォルダーも列挙します。
【引数】
folders
path
(出力) サブ フォルダーのパスの配列
調べるフォルダーのパス。 このフォルダーの中から列挙します
関連
(src)
その他
フォルダーに入っているファイルを一覧することに近い処理を辞書で行います。
フォルダーの中にあるすべてのファイルの
を一覧したテキストファイル。
作成したフォルダー(A)の内容が、以前固定したフォルダー(B)の内容と同じであるかどうかを
チェックするとき、フォルダー(B)に対応する MD5 リストと呼ばれるテキストファイルがあれば、
フォルダー(B) がなくてもチェックができます。
参考
圧縮ファイルを展開したフォルダーやパッチをあてたフォルダーが正しく復元できたことを保証できます。
MD5 リスト
復元したフォルダー
チェック
FileA.txt
FileB.txt
fadc3390060b1ba5ef3bef593b7c930d FileA.txt
60631deb298f23dc7e3a4ada23d8372c FileB.txt
ファイル名
(相対パス)
関連
ファイルが存在しないとき
_FullSet.txt ファイルが存在するフォルダーは、その中の一部のファイルが存在しない可能性が
ありますが、修復することがおそらく可能です。 _FullSet.txt ファイルの内容は MD5リストです。
存在するファイルに関する MD5リスト(ファイル名の例: ExistingFiles.txt)から同じハッシュ値(MD5)
のファイルを探し、存在すればコピーして修復できます。
ファイル名
(相対パス)
2015-12-28T11:13:34+09:00 fadc3390060b1ba5ef3bef593b7c930d FileA.txt
2016-02-20T11:01:04+09:00 60631deb298f23dc7e3a4ada23d8372c FileB.txt
MD5 リスト、タイムスタンプ付き
タイムスタンプ
参考
他にもあります。
_FullSet.txt ファイルが存在するフォルダーから、別のフォルダーにコピーするとき、コピー元を修復
しなくても、コピー先を完全なフォルダーにすることができます。
参考
の Fragment と Defragment。
関連
空のフォルダーも MD5 リストに含めます。 その MD5 値は、0が32文字です(vbslib の仕様)。
また、その値は、get_ToolsLibConsts().EmptyFolderMD5 から参照できます。 タイムスタンプ
は、常に2001-01-01T00:00:00+00:00 (vbslib の仕様)で、
get_ToolsLibConsts().EmptyFolderTimeStamp から参照できます。
2001-01-01T00:00:00+00:00 00000000000000000000000000000000 EmptyFolder
VBScript
Set tc = get_ToolsLibConsts()
If hash_value = tc.EmptyFolderMD5 Then _
    :
If time_stamp = tc.EmptyFolderTimeStamp Then _
    :
の1行
も 0が32文字です(vbslib の仕様)。
ただし、