(for Internet Explorer)
Function  new_PathDictionaryClass_fromXML( path_XML_Elements as IXMLDOMNodeList,
    AttributeName as string,  BasePath as string ) as PathDictionaryClass of IXMLDOMElement
FF-path 属性対応の XML から PathDictionaryClass のオブジェクトを生成します。
【引数】
path_XML_Elements
パスが書かれた XML 要素(タグ)のオブジェクトの集合
AttributeName
通常 "path"。 パスが書かれた XML 属性の名前
テスト
ソース
→ T_Wildcard.vbs
T_PathDictionary_XML
返り値の辞書のアイテムは、XML 要素(タグ)オブジェクト(
→ vbslib.vbs
)になります。
IXMLDOMElement 型
path_XML_Elements 引数には、XML の path 属性がある XML 要素(タグ)の集合を指定します。
PathDictionaryClass のオブジェクト
返り値
XML に書かれた相対パスの基準パス
BasePath
FF-path 属性 (File or Folder as files Path attribute) は、ファイルのパスを指定する XML の path
属性です。
FF-path 属性が使える XML ファイルには、Variable タグを指定することができます。 そして、
path 属性に、Variable タグの参照を指定することができます。 (例:下記の ${ExceptExts})
Except タグの path 属性にも、Variable タグの参照を指定することができます。
Except タグを使えば、サブフォルダーの中にあるファイルのうち、指定したファイルやフォルダーを
対象外にすることができます。 Except タグは、FF-path 属性に対応したタグの子ノードとして配置
してください。 ワイルドカードを使って拡張子を指定することができます。 複数指定するときは、
コンマで区切ってください。 相対パスの基準は、XML ファイルがあるフォルダーです。
XML ファイルの仕様によっては、path 属性を持つタグに path 属性以外の属性を指定することが
できます。 (例:下記の Folder タグの attr 属性)
path 属性を持つタグの名前は、"Folder" や "File" 以外の可能性があります。
ファイルを指定する属性が、path 属性でない可能性もあります。
それぞれの名前は、設定する XML ファイルの仕様を参照してください。
関連
が使えます。
<Root>
    <Variable name="${ExceptExts}" value="*.obj, *.bak"/>

    <File path="Sample.txt"/>
    <Folder path="SubFolder" attr="ABC">
        <Except path="${ExceptExts}"/>
        <Except path="SubFolder\Debug"/>
    </Folder>
</Root>
C:\FolderA\Sample.xml
Variable name
value
Except
Except
緑色の文字の名前は、FF-path 属性、または Variable タグによって定義された名前です。
上記は、Sample.txt ファイルと、SubFolder フォルダーとそのサブフォルダーの中にあるすべての
ファイルのうち、拡張子が obj と bak のファイルと、SubFolder\Debug フォルダーの中のファイルを
除いたファイルを、指定したことになります。
赤色の文字の名前は、XML ファイルの種類によって異なります。
Folder path
path
path
File path
(new_PathDictionaryClass_fromXML 関数に指定します。)
フォルダーの中の一部のファイルやフォルダーに対して、特別な設定を XML に記述することが
できます。 記述する順番には依存しません。 子ノードの記述が優先されます。
<Folder path="Folder" attr="target">
<Folder path="Folder\back_up" attr="not_target">
サンプル
    path_of_XML = "Files\Files1.xml"
    base_path = GetParentFullPath( path_of_XML )
    Set root = LoadXML( path_of_XML, Empty )

    Set dic = new_PathDictionaryClass_fromXML( root.selectNodes( "Folder | File" ), "path", _
        base_path )

    Assert  IsSameArray( dic.FilePaths, Array( _
        "Sample.txt", "SubFolder\A.c", "SubFolder\Sub\A.c" ) )

    For Each  key  In dic.FilePaths
        Assert  dic( key ).getAttribute( "attr" ) = "ABC"
    Next
new_PathDictionaryClass_fromXML
selectNodes
下記 Sample.xml の path 属性と Except タグをリードします。
    Set paths = new PathDictionaryClass
    paths.BasePath = "C:\FolderA"
    Set paths( "Sample.txt" ) = file_tag
    Set paths( "SubFolder" ) = folder_tag
    paths.AddRemove  "*.obj"
    paths.AddRemove  "*.bak"
    paths.AddRemove  "SubFolder\Debug"
上記の XML は、下記のコードでできる PathDictionary ができます。
attr="target" の設定は、Folder フォルダーとそのサブ フォルダーが対象ですが、
Folder\back_up フォルダーは対象外です。
Except タグで対象外にしたフォルダーの中のサブフォルダーやファイルを対象にするときは、
Except タグの親ノードの兄弟ノードに指定してください。
    <Folder path="A">
        <Except path="A\B"/>
    </Folder>
    <Folder path="A\B\C"/>
A        対象
A\1      対象
A\B      対象外
A\B\1    対象外
A\B\C    対象
A\B\C\1  対象
File, Folder, Except タグに
書かれた相対パスの基準は
すべて同じです。
ファイルのパス、フォルダーのパス、ワイルドカードの間の優先順位を下記に示します。
上にあるほど優先度が高いです。 たとえば、あるファイルが、指定したワイルドカードにマッチ
しつつ、指定したフォルダーの中にあるときは、優先順位の高いワイルドカードを指定した XML
の設定がそのファイルに対して使われます。
・ファイルのパス(長い)
・ファイルのパス(短い)
・ワイルドカードがあるパス(\ 記号を含み、長い)
・ワイルドカードがあるパス(\ 記号を含み、短い)
・ワイルドカードがあるパス(\ 記号を含まず、長い)
・ワイルドカードがあるパス(\ 記号を含まず、短い)
・フォルダーのパス(長い)
・フォルダーのパス(短い)
フォルダーの中にあるファイルが、指定されたか指定されなかったかが期待と異なるときは、
XML に下記の Debug タグを追加して、キーとファイル パスの関連を一覧表示してください。
    *\Debug\ => Debug\a.obj
    *\Debug\ => Debug\b.obj
    . => a.c
    . => b.c
<Debug  path_dictionary_scan_log="yes"/>
一覧表示
XML
path_dictionary_scan_log
ファイル名のワイルドカードがあるパスより、フォルダーのパスを優先したいときは、Folder\*
のように指定してください。
Function  GetPathDictionariesFromXML( path_XML_Elements as IXMLDOMNodeList,
    AttributeName as string,  BasePath as string,  MapAttributeName as string )
    as dictionary of PathDictionaryClass of IXMLDOMElement
複数の map からなる
【引数】
path_XML_Elements
パスが書かれた XML 要素(タグ)のオブジェクトの集合
AttributeName
通常 "path"。 パスが書かれた XML 属性の名前
返り値
XML に書かれた相対パスの基準パス
BasePath
のオブジェクトの辞書。キーは、map 属性の値
MapAttributeName
通常 "map"。 map 属性が書かれた XML 属性の名前
複数の map に対応した
です。
単一の map の場合、フォルダー(A) にだけ設定があるとき、そのサブ フォルダーまたはファイル(B)
の設定は、(A) から継承されますが(同じ設定になりますが)、(A) と (B) で異なる map を指定した場合、
(B) の設定は、(A) から継承されません。
path
attr
"Folder"
"Folder\A.txt"
"Folder\back_up\A.txt"
"targetB"
"targetB"
"targetB"
テスト
ソース
→ T_Wildcard.vbs
T_PathDictionaries_XML
→ vbslib.vbs
XML の map 属性は、パスを指定する要素の親要素や、さらにその親要素…、に設定することもできます。
<Parent map="B">
<Folder path="Folder" attr="targetB">
</Parent>
map 属性を指定しなかったときは、GetPathDictionariesFromXML の返り値の辞書のキーは "" になります。
から PathDictionaryClass のオブジェクトを生成します。
map は、XML の map 属性に設定し、返り値(辞書型)のキーに入ります。
map 属性がないXML タグの設定値は、返り値(辞書型)のキーが "" のアイテムに入ります。
<Folder path="Folder"         attr="target">
<Folder path="Folder"         attr="targetB"  map="B">
<Folder path="Folder\back_up" attr="not_target">
map="B"
map の設定があると、map ごとに XML ファイルを分けたようになります。
<Folder path="Folder"         attr="target">
<Folder path="Folder\back_up" attr="not_target">
<Folder path="Folder"  attr="targetB"  map="B">
map = ""
map = "B"
"not_target"
"target"
"target"
"Folder\back_up\A.txt"
"Folder\A.txt"
attr
path
"Folder"
ソース
→ vbslib.vbs
Function  new_PathDictionaryClass( in_Path as variant ) as PathDictionaryClass
典型的な PathDictionaryClass のオブジェクトを生成します。
【引数】
in_Path
ファイルやフォルダーのパス
返り値
PathDictionaryClass のオブジェクト
Set paths = new_PathDictionaryClass( "Folder" )
サンプル
in_Path 引数には、文字列、文字列の配列、PathDictionaryClass のいずれかを指定できます。
Set paths = new_PathDictionaryClass( Array( "FolderA", "FolderB" ) )
Set paths = new_PathDictionaryClass( "Folder" )
Set paths2 = new_PathDictionaryClass( paths )
Assert  paths is paths2
Function  new_PathDictionaryClass_withRemove( in_BasePath as string,
    in_RemovePathArray as array of string,  in_DictionaryItem as Object )
    as PathDictionaryClass
ソース
→ vbslib.vbs
除外するファイルやフォルダーがある、1つのフォルダーの PathDictionaryClass のオブジェクトを生成します。
【引数】
in_BasePath
ベースとなる1つのフォルダー
in_RemovePathArray
除外するファイルやフォルダーの相対パスの配列、または Empty
PathDictionaryClass のオブジェクト
返り値
生成する辞書のすべての Item に設定するオブジェクト
in_DictionaryItem
サンプル
    Set dic = new_PathDictionaryClass_withRemove( "Folder", Array( "*.bak" ), Nothing )
    Assert  dic.BasePath = "C:\Folder"
    Assert  IsSameArray( dic.Keys, Array( "." ) )
in_RemovePathArray 引数に指定する相対パスの基準フォルダーは、in_BasePath です。
    Assert  GetBasePath( "C:\Folder" ) = "C:\Folder"
Function  GetBasePath( in_StringOrObject as variant ) as string
ベースのパスを返します。
【引数】
in_StringOrObject
文字列、または、
ベースのパス
返り値
関連
サンプル
ソース
    Set paths = new PathDictionaryClass
    paths.BasePath = "C:\BaseFolder"

    Assert  GetBasePath( paths ) = "C:\Folder"
in_StringOrObject 引数が文字列のときは、その文字列を返します。
PathDictionaryClass 型のときは、BasePath プロパティを返します。
→ vbslib.vbs
    Assert  GetFullPath( GetBasePath( paths ), Empty ) = "C:\Folder\sub"
GetBasePath
GetBasePath
GetBasePath
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
を True に設定すると、辞書のキーをABC順にソートします。
LeafPathDictionary は、キーを「ファイル、または、空のフォルダーのパス」とした辞書です。
型は、標準で用意されている辞書と同じです。
キーに設定したパスは、ファイルまたはフォルダーが存在しない可能性があります。
LeafPathDictionary のアイテム(NameOnlyClass のオブジェクト)の Name プロパティは、
キーと同じパス、または、存在するファイルまたはフォルダーへのパスです。
キーに関連付けられたアイテムは、ユーザーが自由に設定できます。
    Set dic( "To2.txt" ) = dic( "To.txt" )
    Set dic.Remove  "To.txt"
    Const  NotCaseSensitive = 1
    Set dic = CreateObject( "Scripting.Dictionary" )
    dic.CompareMode = NotCaseSensitive

    Set dic( "To.txt" ) = new_NameOnlyClass( "From.txt", Empty )
辞書のアイテムを変更することで、コピー元を変更することができます。
    Set dic( "To.txt" ) = new_NameOnlyClass( "From2.txt", Empty )
辞書のキーを変更することで、コピー先を変更することができます。
アイテムにあるパスから、キーにあるパスに、ファイルをコピーすることで、多くのファイルを集める処理に
使えます。 ファイルを置き換えるパッチをあてるときにも使えます。
フォルダーから、
を生成します
キーに書かれたパスを変更します
ファイルまたはフォルダーをコピーします
テスト
→ T_LeafPath.vbs
T_LeafPath
関連
False に設定しても、下記のコードのようにソートすることはできます。
QuickSortDicByKey  dic
関連
LeafPathDictionary のアイテムの Name プロパティが文字列の配列のときは、
した内容にする予定であることを示します。 (0) = Base, (1) = Left, (2) = Right  です。
LeafPathDictionary のアイテムの Name プロパティが Empty のときは、削除する予定である
ことを示します。
2つのフォルダーを比較するときに、比較するファイルの名前や場所が異なるときは、関連するパスを
キー、ファイルの内容をアイテムにすることで、比較ができます。 マージするときは、マージした後の
パスに相対パスを合わせたパスをキーにするとよいでしょう。
.LeafPaths
の c.EmptyFolder
LeafPathDictionary を参照する処理によっては、キーしか参照しません。
また、キーをコピー先、アイテムをコピー元として処理することもあります。
パッチ
Function  EnumerateToLeafPathDictionary( in_Path as string ) as dictionary of NameOnlyClass
【引数】
in_Path
フォルダーのパス
返り値
テスト
ソース
フォルダーから、LeafPathDictionary を生成します。
→ T_LeafPath.vbs
T_LeafPath
→ ToolsLib.vbs
返り値の要素のキーと、アイテムの .Name には、フル パスが格納されます。
でソートできます。
Function  IsSameHashValuesOfLeafPathDictionary( _
    in_1stLeafPathDictionary as dictionary,  in_1stBasePath as string, _
    in_2ndLeafPathDictionary as dictionary,  in_2ndBasePath as string )
【引数】
in_1stLeafPathDictionary
in_1stBasePath
LeafPathDictionary が指すすべてのファイルを、もう1つの LeafPathDictionary と比較します。
in_2ndBasePath
比較するベースとする1つ目のフォルダーのパス
in_1stBasePath 引数に対応する2つ目のフォルダーのパス
ファイルが同じ内容かどうかを調べるのに、
を使っています。
in_2ndLeafPathDictionary
1つ目の
2つ目の
返り値
すべてのファイルの内容が同じかどうか
ソース
→ ToolsLib.vbs
、または、Empty
、または、Empty
in_1stLeafPathDictionary 引数、または、in_2ndLeafPathDictionary 引数に、値が Empty の変数を
指定すると、その変数に
が格納されます。
テスト
→ T_LeafPath.vbs
T_LeafPath_IsSameHash
ソース
→ ToolsLib.vbs
テスト
→ T_LeafPath.vbs
T_LeafPath_IsSameName
Function  IsSameFileNamesOfLeafPathDictionary( _
    in_1stLeafPathDictionary as dictionary,  in_1stBasePath as string, _
    in_2ndLeafPathDictionary as dictionary,  in_2ndBasePath as string )
【引数】
in_1stLeafPathDictionary
in_1stBasePath
LeafPathDictionary が指すすべてのファイル名を、もう1つの LeafPathDictionary と比較します。
in_2ndBasePath
比較するベースとする1つ目のフォルダーのパス
in_1stBasePath 引数に対応する2つ目のフォルダーのパス
in_2ndLeafPathDictionary
1つ目の
2つ目の
返り値
すべてのファイルの内容が同じかどうか
、または、Empty
、または、Empty
ファイルの内容は比較しません。
in_1stLeafPathDictionary 引数、または、in_2ndLeafPathDictionary 引数に、値が Empty の変数を
指定すると、その変数に
が格納されます。
Function  GetNotSameFileKeysAsItemsOfLeafPathDictionary( in_LeafPathDictionary as dictionary )
    as array of string
【引数】
in_LeafPathDictionary
LeafPathDictionary のキーとアイテムでファイルの内容が異なるキーを配列にまとめて返します。
キーとアイテムでファイルの内容か異なるキーを配列
返り値
ソース
→ ToolsLib.vbs
テスト
→ T_LeafPath.vbs
T_LeafPath_GetNotSameFiles
ファイルが同じ内容かどうかを調べるのに、
を使っています。
in_LeafPathDictionary 引数のキーとアイテムには、フル パスを格納しておいてください。
Sub  ChangeKeyOfLeafPathDictionary( in_out_LeafPathDictionary as dictionary of NameOnlyClass,
    in_SourcePath as string,  in_DestinationPath as string )
【引数】
in_out_LeafPathDictionary
in_SourcePath
テスト
ソース
コピー先のファイルやフォルダーを移動するように、キーに書かれたパスを変更します。
→ T_LeafPath.vbs
T_LeafPath
→ ToolsLib.vbs
in_DestinationPath
コピー先を変更する前のファイルやフォルダーのパス
コピー先を変更した後のファイルやフォルダーのパス