(for Internet Explorer)
Sub  CopyFilesToLeafPathDictionary(
    in_LeafPathDictionary  as dictionary of NameOnlyClass  or  PatchAndBackUpDictionaryClass,
    in_IsSetItemDestination  as boolean )
【引数】
in_LeafPathDictionary
テスト
ソース
アイテムの Name 属性に書かれたパスから、キーに書かれたパスに、ファイルまたはフォルダーをコピーします。
→ T_LeafPath.vbs
T_LeafPath
→ ToolsLib.vbs
in_IsSetItemDestination
辞書のアイテムをキーと同じ値にするかどうか
→ T_Diff.vbs
T_ThreeWayMerge_Cached
コンフリクトが発生しても E_Conflict エラーにしないようにするには、AttachPatchAndBackUpDictionary
の in_out_Options 引数に、ThreeWayMergeOptionClass::IsEnableToRaiseConflictError = False を指定
します。
in_LeafPathDictionary 引数のキーとアイテムには、フル パスを格納しておいてください。
in_LeafPathDictionary 引数のアイテムの Name プロパティが Empty のときは、削除します。
でいえば、Name(0)〜Name(2) は、
LeafPathDictionary のアイテムの Name プロパティが文字列の配列のときは、
Name(0) = Base (real),  Name(1) = Left (real),  Name(2) = Right (real), Name(3) = 
または、Empty です。
PatchAndBackUpDictionaryClass
Name(0) = back_up (real),  Name(1) = target (real),  Name(2) = patch (real) です。
します。
でアタッチしたパッチを実際のファイルに反映するときにも使います。
→ T_LeafPath.vbs
テスト
ソース
→ ToolsLib.vbs
Sub  RemoveKeyOfEmptyItemInLeafPathDictionary( in_out_LeafPathDictionary as dictionary of NameOnlyClass,
    in_IsDeleteFile as boolean )
【引数】
in_out_LeafPathDictionary
in_IsDeleteFile
アイテムの Name プロパティが Empty の辞書の要素をすべて除外します。
除外したキーに書かれたパスのファイルを削除するかどうか
Set dic = Dict(Array( "C:\FolderA\a.txt", new_NameOnlyClass( Empty, Empty ) ))
RemoveKeyOfEmptyItemInLeafPathDictionary  dic, True

Assert  not dic.Exists( "C:\FolderA\a.txt" )
Assert  not exist( "C:\FolderA\a.txt" )
サンプル
T_LeafPath_RemoveEmpty
Sub  NormalizeLeafPathDictionary( in_out_LeafPathDictionary as dictionary of NameOnlyClass )
【引数】
in_out_LeafPathDictionary
フォルダーのパスと、その中のファイルのパスがあるとき、フォルダーのパスを除外します。
    Const  NotCaseSensitive = 1
    Set dic = CreateObject( "Scripting.Dictionary" )
    dic.CompareMode = NotCaseSensitive

    Set dic( "C:\Folder" )          = new_NameOnlyClass( "C:\Folder", Empty )
    Set dic( "C:\Folder\File.txt" ) = new_NameOnlyClass( "C:\Folder\File.txt", Empty )

    NormalizeLeafPathDictionary  dic
        '// キーが "C:\Folder" のアイテムが除外されます。
サンプル
LeafPathDictionary は、キーを「ファイル、または、空のフォルダーのパス」とした辞書であることが、
正規の状態です。 正規の状態にしなければ、一部の関数が正しく動作しません。
→ T_LeafPath.vbs
テスト
ソース
→ ToolsLib.vbs
T_LeafPath_Normalize
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。
Sub  MakeFolderMD5List( in_FolderPath as string,  in_MD5ListFilePath as string,  in_Option )
後でフォルダーが正しく復元できたかどうかをチェックできるように、MD5 リストを作成します。
【引数】
in_FolderPath
in_MD5ListFilePath
対象のフォルダーのパス、またはその辞書
作成する MD5 リストのファイルパス
関連
テスト
ソース
T_MD5List
→ T_fc.vbs
→ ToolsLib.vbs
ファイル名が Ascii 文字だけのときは、Ascii 形式テキストファイルができます。
Ascii 文字以外が含まれるときは、Unicode 形式テキストファイルができます。
in_FolderPath 引数 - 複数の対象フォルダー
複数の対象のフォルダーに対する MD5リストを1つのファイルに出力するときは、
in_FolderPath 引数に辞書型を指定します。
・Key: MD5リストに含まれるパスの左に付ける文字列
・Item: 対象のフォルダーのパス
202cb962ac59075b964b07152d234b70 %A%\example.txt
fd758aae4cede6a4d6e44ef59b18e799 %B%\example.txt
MD5List.txt:
MakeFolderMD5List  "C:\Target", "MD5List.txt", Empty  '// Write to "MD5List.txt"
サンプル
MakeFolderMD5List  Dict(Array( "%A%\", "C:\TargetA", "%B%\", "C:\TargetB" )), _
    "MD5List.txt", Empty
サンプル
対象フォルダーに含まれる MD5リスト
in_Option
対象フォルダーの中に MD5リストを作成することはできますが、
そのMD5リストの中に作成しようとしている MD5リストを含めることはできません。
なぜなら、MD5リストのMD5が作成する前のMD5になってしまうからです。
Empty
パスでソートします。
MD5 リストの中の相対パスの基準フォルダーは、in_FolderPath 引数です。
tc.IncludeFullSet
tc.FasterButNotSorted
ソートしません。 やや高速に処理します。
に使えなくなります。
には使えます。
とも使えなくなります。
があるフォルダーは、ファイルを列挙せず _FullSet.txt の内容を読みます。
tc.FasterButNotSorted と or で同時に指定してください。
tc.TimeStamp
MD5 リストにファイルの更新日時も含めます。
tc は、get_ToolsLibConsts() です。
で使えるようになります。
tc.BasePathIsList
MD5 リストの中の相対パスの基準フォルダーは、in_MD5ListFilePath 引数の
親フォルダーです。