3 ' vbslib ver3.00 Sep.22, 2009
\r
4 ' Copyright (c) 2008-2009, T's-Neko at Sage Plaisir 21 (Japan)
\r
5 ' All rights reserved. Based on 3-clause BSD license.
\r
9 g_RepliCmp_Path = g_SrcPath
\r
12 Const LimitStartLines_Default = 1000
\r
13 Const MaxByteOfLine_Default = 4096
\r
14 Const LimitReplaceLines_Default = 1000
\r
16 Const NotMatchErr = 101
\r
18 Const ReplaceErr = 103
\r
22 '********************************************************************************
\r
23 ' <<< [RepliCmp] >>>
\r
24 '********************************************************************************
\r
25 Sub RepliCmp( FolderPaths, FileNames, Opt )
\r
27 Dim folders, folder, folder_path, f, file_name, path, i_file, i_folder, b
\r
29 Dim diffs_txt_f, merge_vbs_f
\r
30 Redim repli_files( UBound(FileNames) + 1 )
\r
35 '//=== Check parameters
\r
36 For Each folder_path In FolderPaths
\r
37 If not exist( folder_path ) Then Err.Raise 1,,"[RepliCmp]
\93¯
\8aú
\82·
\82é
\83t
\83H
\83\8b\83_
\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\81F"+folder_path
\r
39 For i_file=0 To UBound(FileNames)
\r
40 If IsEmpty( FileNames(i_file) ) Then Err.Raise 1,,"[RepliCmp]
\93¯
\8aú
\82·
\82é
\83t
\83@
\83C
\83\8b\96¼
\82ª
\90Ý
\92è
\82³
\82ê
\82Ä
\82¢
\82Ü
\82¹
\82ñ
\81Ffile("&i_file&")"
\r
44 '//=== Delete out folder
\r
45 If exist( g_sh.SpecialFolders( "desktop" ) + "\_RepliCmp" ) Then
\r
47 i = input( "
\8fo
\97Í
\90æ
\83t
\83H
\83\8b\83_ desktop\_RepliCmp
\82ª
\82·
\82Å
\82É
\82 \82è
\82Ü
\82·
\81B
\8dí
\8f\9c\82µ
\82Ä
\82æ
\82ë
\82µ
\82¢
\82Å
\82·
\82©
\81H[Y/N]" )
\r
48 If i <> "y" and i <> "Y" Then Exit Sub
\r
50 del g_sh.SpecialFolders( "desktop" ) + "\_RepliCmp"
\r
54 '//=== Collect replica files
\r
55 Set repli_files(0) = new RepliCmp_Files : ErrCheck
\r
56 Set repli_files(0).m_Option = Opt
\r
57 For i_file = 0 To UBound(FileNames)
\r
58 Set repli_files(i_file+1) = new RepliCmp_Files : ErrCheck
\r
59 Set repli_files(i_file+1).m_Option = Opt
\r
62 For Each folder_path In FolderPaths
\r
63 echo "Investigating: " + folder_path
\r
65 For Each file_name In FileNames
\r
68 EnumFolderObject folder_path, folders '// [out] folders
\r
69 For Each folder In folders
\r
70 For Each f In folder.Files
\r
71 If StrComp( file_name, f.Name, 1 ) = 0 Then
\r
72 repli_files(i_file).AddFile f.Path
\r
77 If i_folder = 1 and not b Then
\r
78 Err.Raise 1,,"<ERROR msg='
\8ew
\92è
\82Ì
\83t
\83@
\83C
\83\8b\82ª
\83}
\83X
\83^
\81[
\83t
\83H
\83\8b\83_
\82É
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ'" + vbCRLF+_
\r
79 "file='" + file_name + "'/>"
\r
84 i_folder = i_folder + 1
\r
88 '//=== Read and compare files
\r
89 Dim diff_log, out, n_diff
\r
92 Set diff_log = new RepliCmp_DiffLog : ErrCheck
\r
94 desktop = g_sh.SpecialFolders( "desktop" )
\r
95 mkdir desktop + "\_RepliCmp"
\r
97 Set diffs_txt_f = g_fs.CreateTextFile( desktop + "\_RepliCmp\Diffs.txt", True, False )
\r
99 Set merge_vbs_f = g_fs.CreateTextFile( desktop + "\_RepliCmp\Merge.vbs", True, False )
\r
100 WriteVBSLibHeader merge_vbs_f, Empty
\r
102 .WriteLine "Sub main2( Opt, AppKey )"
\r
103 .WriteLine " AppKey.SetWritableMode F_IgnoreIfWarn"
\r
105 .WriteLine " Dim sync_files : Set sync_files = new SyncFiles" : ErrCheck
\r
106 .WriteLine " Set opt = new Merge_Option" : ErrCheck
\r
108 .WriteLine " opt.m_EditorPath = """ + Opt.m_EditorPath + """"
\r
109 .WriteLine " opt.m_DiffPath = """ + Opt.m_DiffPath + """"
\r
111 .WriteLine " Set sync_files.m_MergeOption = opt"
\r
115 For i_file = 0 To UBound(FileNames)
\r
116 echo "Investigating: " + g_fs.GetFileName( repli_files(i_file).m_Files(0).m_Path )
\r
118 repli_files(i_file).OutDiff out, diffs_txt_f, merge_vbs_f
\r
119 If diff_log.m_NSameGroup >= 2 Then n_diff = n_diff + 1
\r
120 repli_files(i_file) = Empty
\r
124 .WriteLine " sync_files.RunMergePrompt"
\r
125 .WriteLine "End Sub"
\r
127 merge_vbs_f = Empty
\r
128 diffs_txt_f = Empty
\r
131 copy g_vbslib_folder + "*", desktop + "\_RepliCmp\vbslib"
\r
134 del desktop + "\_RepliCmp"
\r
135 echo "No different file."
\r
137 Set f = g_fs.CreateTextFile( desktop + "\_RepliCmp\readme.txt", True, False )
\r
138 f.WriteLine "
\8d·
\95ª
\8fó
\8bµ
\82Í
\81ADiffs.txt
\83t
\83@
\83C
\83\8b\82É
\8f\91\82©
\82ê
\82Ä
\82¢
\82Ü
\82·
\81B"
\r
139 f.WriteLine "Merge.vbs
\82ð
\8eÀ
\8ds
\82·
\82é
\82Æ
\81A
\83}
\81[
\83W
\8dì
\8bÆ
\82ð
\95â
\8f\95\82·
\82é
\83E
\83B
\83\93\83h
\83E
\82ª
\8aJ
\82«
\82Ü
\82·
\81B"
\r
142 If not Opt.m_bSilent Then
\r
143 Setting_openFolder g_sh.SpecialFolders( "desktop" ) + "\_RepliCmp"
\r
145 echo "
\83}
\81[
\83W
\8dì
\8bÆ
\82ð
\8ds
\82¤ _RepliCmp
\83t
\83H
\83\8b\83_
\82ð
\81A
\83f
\83X
\83N
\83g
\83b
\83v
\82É
\8dì
\90¬
\82µ
\82Ü
\82µ
\82½
\81B"
\r
146 echo "
\82Â
\82Ã
\82«
\82Í
\81Areadme.txt
\83t
\83@
\83C
\83\8b\82Ì
\93à
\97e
\82ð
\8eQ
\8fÆ
\82µ
\82Ä
\82
\82¾
\82³
\82¢
\81B"
\r
152 '*-------------------------------------------------------------------------*
\r
153 '*
\81\9f<<<< [RepliCmp_Files] Class >>>> */
\r
154 '*-------------------------------------------------------------------------*
\r
157 Class RepliCmp_Files
\r
161 Private Sub Class_Initialize
\r
166 '********************************************************************************
\r
167 ' <<< [RepliCmp_Files::AddFile] >>>
\r
168 '********************************************************************************
\r
169 Public Sub AddFile( Path )
\r
170 Dim f : Set f = new RepliCmp_File : ErrCheck
\r
172 ReDim Preserve m_Files( UBound( m_Files ) + 1 )
\r
173 Set m_Files( UBound( m_Files ) ) = f
\r
179 '********************************************************************************
\r
180 ' <<< [RepliCmp_Files::OutDiff] >>>
\r
181 '********************************************************************************
\r
182 Public Sub OutDiff( out_DiffLog, DiffsTxtFile, MergeVbsFile )
\r
185 fname = g_fs.GetFileName( Me.m_Files(0).m_Path )
\r
188 '//=== Compare and set same group
\r
189 Dim i, j, i_same_group
\r
192 For i=0 To UBound( Me.m_Files )
\r
193 If IsEmpty( Me.m_Files(i).m_ISameGroup ) Then
\r
194 Me.m_Files(i).m_ISameGroup = i_same_group
\r
195 For j=i+1 To UBound( Me.m_Files )
\r
196 If IsEmpty( Me.m_Files(j).m_ISameGroup ) Then
\r
197 If fc_r( Me.m_Files(i).m_Path, Me.m_Files(j).m_Path, "nul" ) Then _
\r
198 Me.m_Files(j).m_ISameGroup = i_same_group
\r
201 i_same_group = i_same_group + 1
\r
204 i_same_group = i_same_group - 1
\r
207 '//=== Out different files
\r
210 If i_same_group = 1 Then
\r
211 '// All files are same
\r
214 '//=== Write fname+" diffs.txt"
\r
215 Set f = DiffsTxtFile
\r
216 f.WriteLine "[" + fname + "]"
\r
217 f.WriteLine "FilesCount = " & UBound( Me.m_Files ) + 1
\r
218 f.WriteLine "SameFileGroupsCount = " & i_same_group
\r
219 For i=0 To UBound( Me.m_Files )
\r
220 f.WriteLine "File" & Me.m_Files(i).m_ISameGroup & " = " & Me.m_Files(i).m_Path
\r
225 '//=== Write "Merge "+fname+".txt"
\r
226 Set f = MergeVbsFile
\r
228 For i=0 To UBound( Me.m_Files )
\r
229 If j = Me.m_Files(i).m_ISameGroup Then
\r
230 f.WriteLine " sync_files.AddRepliFile """+Me.m_Files(i).m_Path+""""
\r
235 For i=0 To UBound( Me.m_Files )
\r
236 If j = Me.m_Files(i).m_ISameGroup Then
\r
239 f.WriteLine " sync_files.AddSameFile """+Me.m_Files(i).m_Path+""""
\r
242 f.WriteLine " sync_files.NextSyncFile"
\r
248 out_DiffLog.m_NSameGroup = i_same_group
\r
255 '*-------------------------------------------------------------------------*
\r
256 '*
\81\9f<<<< [RepliCmp_File] Class >>>> */
\r
257 '*-------------------------------------------------------------------------*
\r
260 Class RepliCmp_File
\r
262 Public m_ISameGroup
\r
267 '*-------------------------------------------------------------------------*
\r
268 '*
\81\9f<<<< [RepliCmp_DiffLog] Class >>>> */
\r
269 '*-------------------------------------------------------------------------*
\r
272 Class RepliCmp_DiffLog
\r
273 Public m_NSameGroup
\r
279 '*-------------------------------------------------------------------------*
\r
280 '*
\81\9f<<<< [RepliCmp_Option] Class >>>> */
\r
281 '*-------------------------------------------------------------------------*
\r
284 Class RepliCmp_Option
\r
285 Public m_EditorPath
\r
293 '*-------------------------------------------------------------------------*
\r
294 '*
\81\9f<<<< (PartCmp_Option)
\83N
\83\89\83X >>>> *
\r
295 '*-------------------------------------------------------------------------*
\r
297 Class PartCmp_Option
\r
298 Public ExceptFolder
\r
303 Public LimitStartLines
\r
304 Public MaxByteOfLine
\r
306 Private Sub Class_Initialize
\r
307 LimitStartLines = LimitStartLines_Default
\r
308 MaxByteOfLine = MaxByteOfLine_Default
\r
315 '********************************************************************************
\r
316 ' <<< [PartCmp_main] >>>
\r
317 '********************************************************************************
\r
318 Sub PartCmp_main( Opt )
\r
320 Dim PartPath, WholePath, StartTag
\r
324 If IsEmpty( Opt ) Then Set Opt = new PartCmp_Option : ErrCheck
\r
327 '//===
\88ø
\90\94\82Ì
\8eæ
\93¾
\82Æ
\83`
\83F
\83b
\83N
\r
328 On Error Resume Next
\r
329 PartPath = WScript.Arguments.Unnamed(0)
\r
330 WholePath = WScript.Arguments.Unnamed(1)
\r
331 StartTag = WScript.Arguments.Unnamed(2)
\r
332 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
335 echo "PartCmp part_file whole_file start_tag"
\r
337 echo "[ERROR] (" & en & ") " & ed
\r
342 Opt.bSubFolder = ArgumentExist( "S" )
\r
343 Opt.ExceptFolder = WScript.Arguments.Named.Item("E")
\r
344 If Not IsEmpty( Opt.ExceptFolder ) Then Opt.ExceptFolder = g_fs.GetAbsolutePathName( Opt.ExceptFolder )
\r
346 Opt.BatVar = WScript.Arguments.Named.Item("B")
\r
347 If Not IsEmpty( Opt.BatVar ) Then
\r
348 rep_n = InStr( Opt.BatVar, "=" )
\r
350 echo "[ERROR] /B option: not found ="
\r
353 Opt.BatPath = Mid( Opt.BatVar, rep_n + 1 )
\r
354 Opt.BatVar = Left( Opt.BatVar, rep_n - 1 )
\r
357 If PartCmp_compareFiles( WholePath, PartPath, StartTag, Opt ) Then
\r
365 '********************************************************************************
\r
366 ' <<< [PartCmp_compareFiles] >>>
\r
367 '********************************************************************************
\r
368 Function PartCmp_compareFiles( WholePath, PartPath, StartTag, Opt )
\r
369 Dim SamePartPath, SameCollection
\r
370 Dim rep_n, b, en, ed, s
\r
372 IF IsEmpty( Opt ) Then Set Opt = new PartCmp_Option : ErrCheck
\r
375 '//===
\8f\88\97\9d\82Ì
\93à
\97e
\82ð
\95\
\8e¦
\82·
\82é
\r
376 If Opt.bSubFolder Then s = "with" Else s = "without"
\r
378 echo "PartStartTag: """ & StartTag & """"
\r
379 echo "MasterPartFile: """ & PartPath & """"
\r
381 echo "Investigating in """ & GetAbsPath( WholePath, g_sh.CurrentDirectory ) _
\r
382 & """ " & s & " sub folder ..."
\r
386 '//===
\94ä
\8ar
\82·
\82é
\83t
\83@
\83C
\83\8b\82ð fnames
\82É
\97ñ
\8b\93\82·
\82é
\r
387 Dim folder, fname, fnames()
\r
390 If Opt.bSubFolder Then
\r
391 ExpandWildcard WholePath, F_File Or F_SubFolder, folder, fnames
\r
393 ExpandWildcard WholePath, F_File, folder, fnames
\r
396 Set SameCollection = New ArrayDictionary : ErrCheck
\r
399 '//===
\83t
\83@
\83C
\83\8b\82ð
\94ä
\8ar
\82·
\82é
\r
401 For Each fname in fnames
\r
403 If IsEmpty( Opt.ExceptFolder ) Then b = True _
\r
404 Else b = ( Opt.ExceptFolder <> Left( g_fs.BuildPath( folder, fname ), Len(Opt.ExceptFolder) ) )
\r
407 On Error Resume Next
\r
409 PartCmp_compareFile g_fs.BuildPath( folder, fname ), PartPath, StartTag, Opt, SamePartPath
\r
411 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
414 If IsWildcard( WholePath ) Then echo "Same: " + g_fs.BuildPath( folder, fname )
\r
415 If IsWildcard( PartPath ) Then
\r
416 echo " matched part file: " + g_fs.GetFileName( SamePartPath )
\r
417 SameCollection.Add SamePartPath, g_fs.BuildPath( folder, fname )
\r
421 ElseIf en = NotMatchErr Then
\r
422 ElseIf en = DiffErr Then
\r
424 If IsWildcard( WholePath ) Then echo "Diff: " + g_fs.BuildPath( folder, fname ) _
\r
426 If IsWildcard( PartPath ) Then
\r
427 SameCollection.Add "*", g_fs.BuildPath( folder, fname )
\r
429 '//=== /B
\83I
\83v
\83V
\83\87\83\93\82É
\82æ
\82é
\83o
\83b
\83`
\83t
\83@
\83C
\83\8b\8fo
\97Í(1)
\r
430 If Not IsEmpty(Opt.BatVar) Then
\r
431 Set f = g_fs.CreateTextFile( Opt.BatPath, True, False )
\r
432 f.WriteLine "set " + Opt.BatVar + "=" + g_fs.BuildPath( folder, fname )
\r
435 PartCmp_compareFiles = False
\r
445 '//=== /B
\83I
\83v
\83V
\83\87\83\93\82É
\82æ
\82é
\83o
\83b
\83`
\83t
\83@
\83C
\83\8b\8fo
\97Í(2)
\r
446 If Not IsEmpty(Opt.BatVar) Then
\r
447 Set f = g_fs.CreateTextFile( Opt.BatPath, True, False )
\r
448 b = False : If IsWildcard( PartPath ) Then b = (SameCollection.m_Dic.Exists("*"))
\r
450 f.WriteLine "set " + Opt.BatVar + "=" + SameCollection.m_Dic.Item("*").m_Array(0)
\r
452 f.WriteLine "set " + Opt.BatVar + "="
\r
458 '//===
\82P
\82Â
\82à start_tag
\82É
\83q
\83b
\83g
\82µ
\82È
\82©
\82Á
\82½
\82Æ
\82«
\82Ì
\83\81\83b
\83Z
\81[
\83W
\82ð
\8fo
\82·
\r
460 If IsWildcard( WholePath ) Then
\r
461 Err.Raise 1,, "No file matched StartTag."
\r
468 '//===
\90³
\8fí
\8fI
\97¹
\82µ
\82½
\82Æ
\82«
\82Ì
\95\
\8e¦
\82ð
\8ds
\82¤
\r
469 If Not IsWildcard ( PartPath ) Then
\r
470 If IsWildcard( WholePath ) Then echo "All Same." _
\r
472 PartCmp_compareFiles = True
\r
477 WScript.Echo "-----------------------------------------------------"
\r
478 For Each j in SameCollection.m_Dic.Keys()
\r
480 Set a = SameCollection.m_Dic.Item(j)
\r
482 WScript.Echo "Same as " & g_fs.GetFileName(j) & " are " & a.Count & " files"
\r
483 For Each i in a.m_Array
\r
488 If SameCollection.m_Dic.Exists( "*" ) Then
\r
489 Set a = SameCollection.m_Dic.Item("*")
\r
491 WScript.Echo "Others are " & a.Count & " files"
\r
492 For Each i in a.m_Array
\r
497 WScript.Echo "Others are 0 files"
\r
501 WScript.Echo "Total " & SameCollection.Count & " files"
\r
502 PartCmp_compareFiles = False
\r
508 '********************************************************************************
\r
509 ' <<< [PartCmp_compareFile] >>>
\r
510 '********************************************************************************
\r
511 Sub PartCmp_compareFile( WholePath, PartPath, StartTag, Opt, out_SamePartPath )
\r
513 Dim line, i, j, b, part, whole
\r
514 Dim folder, fname, fnames()
\r
516 '//=== WholePath
\82Ì
\83t
\83@
\83C
\83\8b\82Ì
\92\86\82É StartTag
\82ª
\96³
\82¯
\82ê
\82Î
\81A
\83G
\83\89\81[
\83\8c\83x
\83\8b 1
\82Å
\8fI
\97¹
\82·
\82é
\r
517 '//
\82P
\8ds
\82ª256
\95¶
\8e\9a\82ð
\92´
\82¦
\82é
\82Æ
\82«
\82à
\83G
\83\89\81[
\r
518 Set whole = g_fs.OpenTextFile( WholePath )
\r
520 Do Until whole.AtEndOfStream
\r
521 line = whole.ReadLine
\r
522 If Len(line) > Opt.MaxByteOfLine Then Exit Do
\r
524 If InStr( line, StartTag ) <> 0 Then b = True : Exit Do
\r
525 If i >= Opt.LimitStartLines Then Exit Do
\r
529 Err.Raise NotMatchErr,, "Not found """ & StartTag & """ in the start " & Opt.LimitStartLines & _
\r
530 " lines or " & Opt.MaxByteOfLine & " characters in """ & WholePath & """"
\r
534 '//=== PartPath
\82Ì
\83\8f\83C
\83\8b\83h
\83J
\81[
\83h
\82ð
\93W
\8aJ
\82µ
\81A
\88ê
\92v
\82·
\82é PartPath
\82ð
\92T
\82·
\r
535 ExpandWildcard PartPath, F_File, folder, fnames
\r
536 For Each fname in fnames
\r
538 '//=== part
\82Æ while
\82Ì
\88ê
\95\94\82ð
\94ä
\8ar
\82·
\82é
\r
539 Set part = g_fs.OpenTextFile( g_fs.BuildPath( folder, fname ) )
\r
541 If part.ReadLine = line Then
\r
543 Do Until part.AtEndOfStream
\r
544 If whole.AtEndOfStream Then b = False : Exit Do
\r
545 If part.ReadLine <> whole.ReadLine Then b = False : Exit Do
\r
551 If b Then out_SamePartPath = g_fs.BuildPath( folder, fname ) : Exit Sub ' Same
\r
553 '//=== whole
\82ð
\94ä
\8ar
\82·
\82é
\90æ
\93ª
\82É
\96ß
\82·
\r
554 Set whole = g_fs.OpenTextFile( WholePath )
\r
555 For j=1 To i-1 : whole.ReadLine : Next
\r
556 line = whole.ReadLine
\r
559 Err.Raise DiffErr,,"diff"
\r
563 '*-------------------------------------------------------------------------*
\r
564 '*
\81\9f<<<< (PartRep_Option)
\83N
\83\89\83X >>>> *
\r
565 '*-------------------------------------------------------------------------*
\r
567 Class PartRep_Option
\r
568 Public ExceptFolder
\r
572 Public LimitStartLines
\r
573 Public MaxByteOfLine
\r
574 Public LimitReplaceLines
\r
576 Private Sub Class_Initialize
\r
577 LimitStartLines = LimitStartLines_Default
\r
578 MaxByteOfLine = MaxByteOfLine_Default
\r
579 LimitReplaceLines = LimitReplaceLines_Default
\r
586 '********************************************************************************
\r
587 ' <<< [PartRep_main] >>>
\r
588 '********************************************************************************
\r
589 Sub PartRep_main( Opt )
\r
591 Dim FromPath(), ToPath(), DstPath, bReplace, NPair
\r
595 If IsEmpty( Opt ) Then Set Opt = new PartRep_Option : ErrCheck
\r
598 '//===
\88ø
\90\94\82Ì
\8eæ
\93¾
\82Æ
\83`
\83F
\83b
\83N
\r
599 bReplace = ArgumentExist( "G" )
\r
600 Opt.bSubFolder = ArgumentExist( "S" )
\r
601 Opt.ExceptFolder = WScript.Arguments.Named.Item("E")
\r
602 If Not IsEmpty( Opt.ExceptFolder ) Then Opt.ExceptFolder = g_fs.GetAbsolutePathName( Opt.ExceptFolder )
\r
603 NPair = WScript.Arguments.Named.Item("A")
\r
604 If IsEmpty( NPair ) Then NPair = 1 Else NPair = CInt( NPair )
\r
606 Redim FromPath(NPair-1)
\r
607 Redim ToPath(NPair-1)
\r
608 On Error Resume Next
\r
610 FromPath(i) = WScript.Arguments.Unnamed(i*2)
\r
611 ToPath(i) = WScript.Arguments.Unnamed(i*2+1)
\r
613 DstPath = WScript.Arguments.Unnamed(NPair*2)
\r
614 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
617 echo "PartRep [/G][/S][/E:path][/A:n] from_file to_file dst_file"
\r
619 echo "[ERROR] (" & en & ") " & ed
\r
625 FromPath(i) = g_fs.GetAbsolutePathName( FromPath(i) )
\r
626 ToPath(i) = g_fs.GetAbsolutePathName( ToPath(i) )
\r
628 ' DstPath = g_fs.GetAbsolutePathName( DstPath )
\r
630 Opt.bNoConfirm = True
\r
632 PartRep_replaceFiles NPair, FromPath, ToPath, DstPath, bReplace, Opt
\r
637 '********************************************************************************
\r
638 ' <<< [PartRep_replaceFiles] >>>
\r
639 '********************************************************************************
\r
640 Sub PartRep_replaceFiles( NPair, FromPath(), ToPath(), DstPath, bReplace, Opt )
\r
641 Dim rep_n, b, en, ed
\r
643 echo ">PartRep_replaceFiles """ + DstPath + """"
\r
645 If IsEmpty( Opt ) Then Set Opt = new PartRep_Option : ErrCheck
\r
647 If bReplace and (not Opt.bNoConfirm) Then
\r
649 echo "
\95K
\97v
\82È
\82ç
\92u
\82«
\8a·
\82¦
\82æ
\82¤
\82Æ
\82µ
\82Ä
\82¢
\82é
\83t
\83@
\83C
\83\8b\82Ì
\83o
\83b
\83N
\83A
\83b
\83v
\82ð
\8eæ
\82Á
\82Ä
\82
\82¾
\82³
\82¢
\81B"
\r
650 b = input( "
\92u
\82«
\8a·
\82¦
\82ð
\8eÀ
\8ds
\82µ
\82Ü
\82·
\82©
\81H (Y/N)" )
\r
651 If b<>"y" and b<>"Y" Then Err.Raise 1,,"[PartRep]
\83\86\81[
\83U
\82É
\82æ
\82é
\92\86\8e~"
\r
655 '//===
\94ä
\8ar
\82·
\82é
\83t
\83@
\83C
\83\8b\82ð fnames
\82É
\97ñ
\8b\93\82·
\82é
\r
656 Dim folder, fname, fnames()
\r
658 If Opt.bSubFolder Then
\r
659 ExpandWildcard DstPath, F_File Or F_SubFolder, folder, fnames
\r
661 ExpandWildcard DstPath, F_File, folder, fnames
\r
665 '//===
\83t
\83@
\83C
\83\8b\82Ì
\88ê
\95\94\82ð
\92u
\82«
\8a·
\82¦
\82é
\r
667 For Each fname in fnames
\r
669 If IsEmpty( Opt.ExceptFolder ) Then b = True _
\r
670 Else b = ( Opt.ExceptFolder <> Left( g_fs.BuildPath( folder, fname ), Len(Opt.ExceptFolder) ) )
\r
673 On Error Resume Next
\r
675 PartRep_replaceFile NPair, FromPath, ToPath, g_fs.BuildPath( folder, fname ), bReplace, Opt
\r
677 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
680 echo g_fs.BuildPath( folder, fname )
\r
683 ElseIf en = NotMatchErr Then
\r
684 If Not IsWildcard( DstPath ) Then
\r
690 echo g_fs.BuildPath( folder, fname )
\r
691 echo "[ERROR] Fail to replace."
\r
692 echo "[ERROR] (" & en & ") " & ed
\r
698 If bReplace Then echo rep_n & " files replaced." _
\r
699 Else echo rep_n & " files will replace, if /G option"
\r
704 '********************************************************************************
\r
705 ' <<< [PartRep_replaceFile] >>>
\r
706 '********************************************************************************
\r
707 Sub PartRep_replaceFile( NPair, FromPath(), ToPath(), DstPath, bReplace, Opt )
\r
709 Dim line, line2, i, i2, dst_head_n(), from_n(), b, from, to_, dst, tmp
\r
712 Redim dst_head_n( NPair - 1 ), from_n( NPair - 1 )
\r
713 For i_pair=0 To NPair-1 : dst_head_n(i_pair) = 0 : from_n(i_pair) = 0 : Next
\r
716 '//=== DstPath
\82Ì
\83t
\83@
\83C
\83\8b\82Ì
\92\86\82É from_file
\82ª
\96³
\82¯
\82ê
\82Î
\81A
\83G
\83\89\81[
\83\8c\83x
\83\8b 1
\82Å
\8fI
\97¹
\82·
\82é
\r
717 '//
\82P
\8ds
\82ª256
\95¶
\8e\9a\82ð
\92´
\82¦
\82é
\82Æ
\82«
\82à
\83G
\83\89\81[
\r
719 Set dst = g_fs.OpenTextFile( DstPath )
\r
720 Set from = g_fs.OpenTextFile( FromPath(i_pair) )
\r
721 line2 = from.ReadLine : i2 = 0
\r
723 Do Until dst.AtEndOfStream
\r
724 line = dst.ReadLine
\r
725 If Len(line) > Opt.MaxByteOfLine Then Exit Do
\r
727 If line = line2 Then
\r
728 If i2 = 0 Then dst_head_n(i_pair) = i - 1
\r
730 If from.AtEndOfStream Then
\r
731 If i2 > Opt.LimitReplaceLines Then Exit Do
\r
732 from_n(i_pair) = i2
\r
733 If i_pair = NPair-1 Then b = True : Exit Do
\r
735 i_pair = i_pair + 1
\r
736 Set from = g_fs.OpenTextFile( FromPath(i_pair) )
\r
739 line2 = from.ReadLine
\r
742 Set from = g_fs.OpenTextFile( FromPath(i_pair) )
\r
743 line2 = from.ReadLine : i2 = 0
\r
744 If line = line2 Then i2 = 1 : dst_head_n(i_pair) = i - 1 : line2 = from.ReadLine
\r
747 If i >= Opt.LimitStartLines And i2=0 Then Exit Do
\r
751 Err.Raise NotMatchErr,,"Not found """ & FromPath(i_pair) & """ in the start " & Opt.LimitStartLines & _
\r
752 " lines or " & Opt.MaxByteOfLine & " characters in """ & DstPath & """"
\r
756 '//===
\92u
\82«
\8a·
\82¦
\82½
\8cã
\82ª
\91å
\82«
\82·
\82¬
\82È
\82¢
\82©
\83`
\83F
\83b
\83N
\82·
\82é
\r
757 For i_pair=0 To NPair-1
\r
758 Set to_ = g_fs.OpenTextFile( ToPath(i_pair) )
\r
760 Do Until to_.AtEndOfStream
\r
761 line = to_.ReadLine
\r
762 If Len(line) > Opt.MaxByteOfLine Then b = False : Exit Do
\r
764 If i >= Opt.LimitStartLines Then b = False : Exit Do
\r
767 Err.Raise NotMatchErr,,"Too big """ & ToPath(i_pair) & """"
\r
772 '//=== TmpPath =
\88ê
\8e\9e\83t
\83@
\83C
\83\8b\82Ì
\83t
\83@
\83C
\83\8b\96¼
\r
774 TmpPath = g_fs.GetParentFolderName( DstPath ) + "\" + "_PartRepTmp" & i & ".txt"
\r
775 If Not g_fs.FileExists( TmpPath ) And Not g_fs.FolderExists( TmpPath ) Then Exit For
\r
778 Err.Raise ReplaceErr,,"Cannot create """ & TmpPath & """"
\r
784 '//=== tmp, dst, to_
\83t
\83@
\83C
\83\8b\82ð
\8aJ
\82
\r
785 Set tmp = g_fs.CreateTextFile( TmpPath, False, False )
\r
786 Set dst = g_fs.OpenTextFile( DstPath )
\r
787 For i_pair=0 To NPair-1
\r
788 Set to_ = g_fs.OpenTextFile( ToPath(i_pair) )
\r
791 '//=== tmp
\83t
\83@
\83C
\83\8b\82É dst
\83t
\83@
\83C
\83\8b\82Ì StartTag
\82ð
\8aÜ
\82Þ
\8ds
\82æ
\82è
\91O
\82ð
\83R
\83s
\81[
\82·
\82é
\r
792 Do Until dst.AtEndOfStream
\r
793 If dst_head_n(i_pair) = 0 Then Exit Do
\r
794 dst_head_n(i_pair) = dst_head_n(i_pair) - 1
\r
795 tmp.WriteLine dst.ReadLine
\r
799 '//=== tmp
\83t
\83@
\83C
\83\8b\82É to_
\83t
\83@
\83C
\83\8b\91S
\91Ì
\82ð
\81A
\92Ç
\89Á
\83R
\83s
\81[
\82·
\82é
\r
800 Do Until to_.AtEndOfStream
\r
801 tmp.WriteLine to_.ReadLine
\r
803 For i = 1 To from_n(i_pair)
\r
809 '//=== tmp
\83t
\83@
\83C
\83\8b\82É dst
\83t
\83@
\83C
\83\8b\82Ì EndTag
\82ð
\8aÜ
\82Þ
\8ds
\82æ
\82è
\8cã
\82ð
\81A
\92Ç
\89Á
\83R
\83s
\81[
\82·
\82é
\r
810 Do Until dst.AtEndOfStream
\r
811 tmp.WriteLine dst.ReadLine
\r
815 '//=== tmp, dst, to_
\83t
\83@
\83C
\83\8b\82ð
\95Â
\82¶
\82é
\r
816 tmp = Empty : dst = Empty : to_ = Empty
\r
819 '//=== tmp
\83t
\83@
\83C
\83\8b\82ð dst
\83t
\83@
\83C
\83\8b\82É
\83R
\83s
\81[
\82µ
\82Ä
\81Atmp
\83t
\83@
\83C
\83\8b\82ð
\8dí
\8f\9c\82·
\82é
\r
820 Set dst = g_fs.CreateTextFile( DstPath, True, False )
\r
821 Set tmp = g_fs.OpenTextFile( TmpPath )
\r
822 dst.Write tmp.ReadAll
\r
823 tmp = Empty : dst = Empty
\r
825 g_fs.DeleteFile TmpPath
\r