3 ' vbslib ver2.00 2008/8/17
\r
4 ' Copyright (c) 2008, T's-Neko
\r
5 ' All rights reserved. 3-clause BSD license.
\r
9 '********************************************************************************
\r
10 ' <<< Global variables >>>
\r
11 '********************************************************************************
\r
13 Dim g_workfolder, g_Err2, g_echo_on
\r
17 Function InitializeModule
\r
20 Set g_Err2 = New Err2
\r
23 Dim g_InitializeModule
\r
24 Set g_InitializeModule = GetRef( "InitializeModule" )
\r
26 Function FinalizeModule( ThisPath )
\r
27 g_Err2.OnSuccessFinish
\r
29 Dim g_FinalizeModule: Set g_FinalizeModule = GetRef( "FinalizeModule" )
\r
30 Dim g_FinalizeLevel: g_FinalizeLevel = 100 ' If smaller, called early
\r
35 Const F_SubFolder = 4
\r
39 '********************************************************************************
\r
40 ' <<< Error Code >>>
\r
41 '********************************************************************************
\r
43 ' vbObjectError = &h80040000
\r
44 Const E_AssertFail = &h80041001
\r
45 Const E_TestFail = &h80041003
\r
46 Const E_BuildFail = &h80041004
\r
47 Const E_OutOfWorkFolder = &h80041005
\r
48 Const E_ProgTerminated = &hC0000005
\r
49 Const E_NotFoundSymbol = &h80041006
\r
50 Const E_ProgRetNotZero = &h80041007
\r
51 Const E_Unexpected = &h80041008
\r
52 Const E_Other = &h80041009
\r
53 Const E_FileNotExist = 53
\r
54 Const E_EndOfFile = 62
\r
55 Const E_WriteAccessDenied = 70
\r
56 Const E_PathNotFound = 76
\r
60 '********************************************************************************
\r
61 ' <<< File Object >>>
\r
62 '********************************************************************************
\r
68 '*-------------------------------------------------------------------------*
\r
69 '*
\81\9f<<<<
\83\86\81[
\83U
\83C
\83\93\83^
\81[
\83t
\83F
\83C
\83X >>>>
\r
70 '*-------------------------------------------------------------------------*
\r
74 '********************************************************************************
\r
76 ' return: output message
\r
77 '********************************************************************************
\r
78 Function echo( ByVal msg )
\r
81 If IsObject( msg ) Then msg = msg.Value
\r
85 b = False : If Not IsEmpty( g_Test ) Then b = Not IsEmpty( g_Test.m_Log )
\r
86 If b Then g_Test.m_Log.WriteLine msg
\r
92 '********************************************************************************
\r
94 ' return: output message
\r
95 '********************************************************************************
\r
96 Function echo_r( ByVal msg, redirect_path )
\r
98 Const ForAppending = 8
\r
100 If IsObject( msg ) Then msg = msg.Value
\r
102 If g_debug Then WScript.Echo msg
\r
104 If IsEmpty( redirect_path ) Then
\r
105 ElseIf redirect_path = "" Then
\r
106 If Not g_debug Then WScript.Echo msg
\r
108 Set f = g_fs.OpenTextFile( redirect_path, ForAppending, True, False )
\r
117 '********************************************************************************
\r
118 ' <<< [echo_c] >>>
\r
119 '********************************************************************************
\r
121 If g_b_cscript_exe And g_echo_on Then echo msg
\r
126 '********************************************************************************
\r
127 ' <<< [echo_on] >>>
\r
128 '********************************************************************************
\r
139 '********************************************************************************
\r
140 ' <<< [EchoOnOff] >>>
\r
141 '********************************************************************************
\r
146 Private Sub Class_Initialize
\r
150 Private Sub Class_Terminate
\r
157 '********************************************************************************
\r
159 '********************************************************************************
\r
163 Set f = g_fs.OpenTextFile( path )
\r
165 Do Until f.AtEndOfStream
\r
166 WScript.Echo f.ReadLine
\r
172 '********************************************************************************
\r
174 '********************************************************************************
\r
176 input "
\91±
\8ds
\82·
\82é
\82É
\82Í Enter
\83L
\81[
\82ð
\89\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢ . . ."
\r
181 '********************************************************************************
\r
182 ' <<< [pause2] >>>
\r
183 '********************************************************************************
\r
185 If WScript.Arguments.Named("wscript")=1 Then input "Enter
\83L
\81[
\82ð
\89\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢ . . ."
\r
190 '********************************************************************************
\r
192 '********************************************************************************
\r
193 Function input( ByVal msg )
\r
195 input = g_CUI.input( msg )
\r
199 ' Wscript.StdOut.Write msg
\r
201 ' On Error Resume Next
\r
203 ' input = WScript.StdIn.ReadLine
\r
205 ' e = Err.Number : Err.Clear : On Error GoTo 0
\r
207 ' If e <> 62 Then Err.Raise e '62= End Of File (StdIn, ^C)
\r
215 '********************************************************************************
\r
216 ' <<< [SendKeys] Send keyboard code stroke to OS >>>
\r
217 '********************************************************************************
\r
218 Sub SendKeys( ByVal window_title, ByVal keycords, ByVal late_time )
\r
219 WScript.Sleep late_time
\r
220 If window_title <> "" Then g_sh.AppActivate( window_title )
\r
222 g_sh.SendKeys keycords
\r
227 '*-------------------------------------------------------------------------*
\r
228 '*
\81\9f<<<< [CUI] Class >>>>
\r
229 '*-------------------------------------------------------------------------*
\r
233 Public m_Auto_InputFunc ' as string of auto input function name
\r
234 Public m_Auto_Src ' as string of path
\r
235 Public m_Auto_Keys ' as string of auto input keys
\r
236 Public m_Auto_KeyEnter ' as string of the character of replacing to enter key
\r
237 Public m_Auto_DebugCount ' as integer
\r
241 '********************************************************************************
\r
242 ' <<< [CUI::Class_Initialize] >>>
\r
243 '********************************************************************************
\r
244 Private Sub Class_Initialize
\r
245 Me.m_Auto_KeyEnter = "."
\r
246 Me.m_Auto_DebugCount = Empty
\r
251 '********************************************************************************
\r
252 ' <<< [CUI::pause] >>>
\r
253 '********************************************************************************
\r
255 input "
\91±
\8ds
\82·
\82é
\82É
\82Í Enter
\83L
\81[
\82ð
\89\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢ . . ."
\r
260 '********************************************************************************
\r
261 ' <<< [CUI::input] >>>
\r
262 '********************************************************************************
\r
263 Public Function input( ByVal msg )
\r
267 Wscript.StdOut.Write msg
\r
269 On Error Resume Next
\r
271 If Not IsEmpty( m_Auto_Keys ) And m_Auto_Keys <> "" Then
\r
272 If Not IsEmpty( m_Auto_KeyEnter ) Then
\r
273 e = InStr( m_Auto_Keys, m_Auto_KeyEnter )
\r
275 input = m_Auto_Keys
\r
276 m_Auto_Keys = Empty
\r
278 input = Left( m_Auto_Keys, e - 1 )
\r
279 m_Auto_Keys = Mid( m_Auto_Keys, e + 1 )
\r
282 input = m_Auto_Keys
\r
283 m_Auto_Keys = Empty
\r
286 If IsEmpty( m_Auto_DebugCount ) Then
\r
288 ElseIf m_Auto_DebugCount > 1 Then
\r
290 m_Auto_DebugCount = m_Auto_DebugCount - 1
\r
292 Wscript.StdOut.Write input
\r
293 Wscript.StdIn.ReadLine
\r
297 ElseIf IsEmpty( m_Auto_InputFunc ) Then
\r
298 input = Wscript.StdIn.ReadLine
\r
300 If IsEmpty( m_Auto_Src ) Then
\r
301 Set InputFunc = GetRef( m_Auto_InputFunc )
\r
302 If Err.Number = 5 Then WScript.Echo vbCR+vbLF+"Not found function of """+_
\r
303 m_Auto_InputFunc +"""": Err.Clear
\r
304 If Not IsEmpty( InputFunc ) Then input = InputFunc( msg )
\r
306 input = call_vbs_t( m_Auto_Src, m_Auto_InputFunc, msg )
\r
307 If Err.Number = 5 Then WScript.Echo vbCR+vbLF+"Not found function of """+_
\r
308 m_Auto_InputFunc +""" in """+m_Auto_Src+"""" : Err.Clear
\r
309 If IsEmpty( input ) Then Wscript.StdOut.Write msg : input = Wscript.StdIn.ReadLine
\r
313 e = Err.Number : Err.Clear : On Error GoTo 0
\r
315 If e <> 62 Then Err.Raise e '62= End Of File (StdIn, ^C)
\r
323 '********************************************************************************
\r
324 ' <<< [CUI::SetAutoKeysFromMainArg] >>>
\r
325 '********************************************************************************
\r
326 Public Sub SetAutoKeysFromMainArg
\r
327 If IsEmpty( Me.m_Auto_Keys ) Then
\r
328 Me.m_Auto_Keys = WScript.Arguments.Named.Item("autokeys")
\r
329 Me.m_Auto_DebugCount = WScript.Arguments.Named.Item("autokeys_debug")
\r
339 '*-------------------------------------------------------------------------*
\r
340 '*
\81\9f<<<<
\83t
\83@
\83C
\83\8b\91\80\8dì >>>>
\r
341 '*-------------------------------------------------------------------------*
\r
345 '********************************************************************************
\r
346 ' <<< [set_workfolder] Set modifiable base folder path >>>
\r
348 ' - if work path set current directory, path = ""
\r
349 '********************************************************************************
\r
350 Sub set_workfolder( ByVal path )
\r
351 If g_debug Then echo_c "set_workfolder: " + path
\r
356 If Not g_fs.FolderExists( path ) Then Err.Raise E_FileNotExist,"vbslib","Not found """+path+""""
\r
357 g_workfolder = g_fs.GetAbsolutePathName( path )
\r
363 '********************************************************************************
\r
364 ' <<< [WorkFolderStack] Set modifiable base folder path >>>
\r
365 '********************************************************************************
\r
366 Class WorkFolderStack
\r
368 Public m_PrevWorkFolder
\r
370 Private Sub Class_Initialize
\r
371 m_PrevWorkFolder = g_workfolder
\r
374 Private Sub Class_Terminate
\r
375 g_workfolder = m_PrevWorkFolder
\r
378 Public Sub Set_( path )
\r
379 '// If g_debug Then echo_c "set_workfolder: " + path
\r
383 ElseIf path = "." Then
\r
384 g_workfolder = g_sh.CurrentDirectory
\r
386 If Not g_fs.FolderExists( path ) Then Err.Raise E_FileNotExist,"vbslib","Not found """+path+""""
\r
387 g_workfolder = g_fs.GetAbsolutePathName( path )
\r
394 '********************************************************************************
\r
395 ' <<< [chk_in_workfolder] Check not to modify out of working folder >>>
\r
397 ' - If path is out of workfolder, raise error of E_OutOfWorkFolder.
\r
398 '********************************************************************************
\r
399 Sub chk_in_workfolder( ByVal path )
\r
402 If g_workfolder = "" Then
\r
403 Set sh = WScript.CreateObject("WScript.Shell")
\r
404 work = sh.CurrentDirectory
\r
407 work = g_workfolder
\r
409 work = g_fs.BuildPath( work, "a" )
\r
410 work = Left( work, Len(work) - 1 )
\r
412 path = g_fs.GetAbsolutePathName( path )
\r
414 If work <> Left( path, Len( work ) ) Then
\r
415 Err.Raise E_OutOfWorkFolder, "vbslib", "Out of working folder """ & path & """"
\r
422 '********************************************************************************
\r
423 ' <<< [cd] change current directory >>>
\r
426 '********************************************************************************
\r
427 Sub cd( ByVal dir )
\r
430 Set sh = WScript.CreateObject("WScript.Shell")
\r
431 sh.CurrentDirectory = dir
\r
437 '********************************************************************************
\r
438 ' <<< [CurDirStack] >>>
\r
439 '********************************************************************************
\r
444 Private Sub Class_Initialize
\r
445 m_Prev = g_sh.CurrentDirectory
\r
448 Private Sub Class_Terminate
\r
449 g_sh.CurrentDirectory = m_Prev
\r
455 '********************************************************************************
\r
456 ' <<< [pushd] push and change current directory >>>
\r
459 '********************************************************************************
\r
460 Dim g_pushd_stack()
\r
461 Dim g_pushd_stack_n
\r
463 Sub pushd( ByVal dir )
\r
466 g_pushd_stack_n = g_pushd_stack_n + 1
\r
467 Redim Preserve g_pushd_stack( g_pushd_stack_n )
\r
469 Set sh = WScript.CreateObject("WScript.Shell")
\r
470 g_pushd_stack( g_pushd_stack_n ) = sh.CurrentDirectory
\r
471 sh.CurrentDirectory = dir
\r
477 '********************************************************************************
\r
478 ' <<< [popd] pop current directory >>>
\r
479 '********************************************************************************
\r
483 If g_pushd_stack_n < 1 Then Exit Sub
\r
485 Set sh = WScript.CreateObject("WScript.Shell")
\r
486 sh.CurrentDirectory = g_pushd_stack( g_pushd_stack_n )
\r
488 g_pushd_stack_n = g_pushd_stack_n - 1
\r
494 '********************************************************************************
\r
497 ' - src : source file or folder path or wild card
\r
498 ' - dst : destination folder path or renaming file path
\r
500 ' - reference: vbslib.svg#copy
\r
501 '********************************************************************************
\r
502 Sub copy( ByVal src, ByVal dst )
\r
504 If g_fs.FolderExists( dst ) Then
\r
505 chk_in_workfolder g_fs.BuildPath( dst, "a" )
\r
507 chk_in_workfolder dst
\r
511 ' If src had Wild card
\r
512 If IsWildcard( src ) Then
\r
516 If Not g_fs.FolderExists( dst ) Then mkdir dst
\r
517 If Not g_fs.FolderExists( g_fs.GetParentFolderName( src ) ) Then _
\r
518 Err.Raise E_PathNotFound,,"
\83p
\83X
\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\81B"
\r
520 On Error Resume Next
\r
521 g_fs.CopyFile src, dst, True
\r
522 g_fs.CopyFolder src, dst, True
\r
523 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
524 If en = E_PathNotFound Then en = 0
\r
525 If en = E_FileNotExist Then en = 0
\r
526 If en <> 0 Then Err.Raise en,,ed
\r
530 ElseIf g_fs.FileExists( src ) Then
\r
534 If g_fs.FolderExists( dst ) Then
\r
535 dst = g_fs.BuildPath( dst, g_fs.GetFileName( src ) )
\r
537 dst_fo = g_fs.GetParentFolderName( dst )
\r
538 If dst_fo <> "" And Not g_fs.FolderExists( dst_fo ) Then mkdir dst_fo
\r
541 g_fs.CopyFile src, dst, True
\r
545 ElseIf g_fs.FolderExists( src ) Then
\r
547 If Not g_fs.FolderExists( dst ) Then mkdir dst
\r
549 g_fs.CopyFolder src, g_fs.BuildPath( dst, g_fs.GetFileName( src ) ), True
\r
554 g_fs.CopyFile src, dst, True ' Error occurs
\r
561 '********************************************************************************
\r
563 '********************************************************************************
\r
564 Sub move( ByVal src, ByVal dst )
\r
566 If g_fs.FolderExists( dst ) Then
\r
567 chk_in_workfolder g_fs.BuildPath( dst, "a" )
\r
569 chk_in_workfolder dst
\r
573 ' If src had Wild card
\r
574 If IsWildcard( src ) Then
\r
578 If Not g_fs.FolderExists( dst ) Then mkdir dst
\r
579 If Not g_fs.FolderExists( g_fs.GetParentFolderName( src ) ) Then _
\r
580 Err.Raise E_PathNotFound,,"
\83p
\83X
\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ
\81B"
\r
582 On Error Resume Next
\r
583 g_fs.MoveFile src, dst
\r
584 g_fs.MoveFolder src, dst
\r
585 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
586 If en = E_PathNotFound Then en = 0
\r
587 If en = E_FileNotExist Then en = 0
\r
588 If en <> 0 Then Err.Raise en,,ed
\r
592 ElseIf g_fs.FileExists( src ) Then
\r
596 If g_fs.FolderExists( dst ) Then
\r
597 dst = g_fs.BuildPath( dst, g_fs.GetFileName( src ) )
\r
599 dst_fo = g_fs.GetParentFolderName( dst )
\r
600 If Not g_fs.FolderExists( dst_fo ) Then mkdir dst_fo
\r
603 g_fs.MoveFile src, dst
\r
607 ElseIf g_fs.FolderExists( src ) Then
\r
609 If Not g_fs.FolderExists( dst ) Then mkdir dst
\r
611 g_fs.MoveFolder src, g_fs.BuildPath( dst, g_fs.GetFileName( src ) )
\r
616 g_fs.MoveFile src, dst ' Error occurs
\r
623 '********************************************************************************
\r
625 '********************************************************************************
\r
626 Sub ren( src, dst )
\r
628 If g_fs.FileExists( src ) Then
\r
629 Set f = g_fs.GetFile( src )
\r
630 f.Name = g_fs.GetFileName( dst )
\r
632 Set f = g_fs.GetFolder( src )
\r
633 f.Name = g_fs.GetFileName( dst )
\r
639 '********************************************************************************
\r
640 ' <<< [SafeFileUpdate] >>>
\r
641 '********************************************************************************
\r
642 Sub SafeFileUpdate( FromTmpFilePath, ToUpdateFilePath )
\r
643 Dim en,ed,en2,ed2,i,path
\r
646 path = g_fs.GetParentFolderName( ToUpdateFilePath ) + "\" + _
\r
647 g_fs.GetBaseName( ToUpdateFilePath ) + "." & i & "." + g_fs.GetExtensionName( ToUpdateFilePath )
\r
648 If not exist( path ) Then Exit For
\r
650 If exist( path ) Then Err.Raise E_Other,,"
\83o
\83b
\83N
\83A
\83b
\83v
\82Ì
\83t
\83@
\83C
\83\8b\96¼
\82ª
\8dì
\82ê
\82Ü
\82¹
\82ñ
\81B
\81F" + ToUpdateFilePath
\r
652 On Error Resume Next
\r
653 g_fs.CopyFile ToUpdateFilePath, path, False
\r
654 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
655 If en <> 0 Then Err.Raise en,,"
\83o
\83b
\83N
\83A
\83b
\83v
\83R
\83s
\81[
\82É
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½
\81B"+vbCR+vbLF+_
\r
656 "
\83o
\83b
\83N
\83A
\83b
\83v
\8c³
\81F"+ToUpdateFilePath+vbCR+vbLF+ "
\83o
\83b
\83N
\83A
\83b
\83v
\90æ
\81F"+path+vbCR+vbLF+ ed
\r
658 del_to_trashbox path
\r
660 On Error Resume Next
\r
661 g_fs.CopyFile FromTmpFilePath, ToUpdateFilePath, True
\r
662 en2 = Err.Number : ed2 = Err.Description : On Error GoTo 0
\r
664 On Error Resume Next
\r
665 g_fs.DeleteFile FromTmpFilePath
\r
666 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
668 If en2 <> 0 Then Err.Raise en2,,"
\8fã
\8f\91\82«
\83R
\83s
\81[
\82É
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½
\81B
\83S
\83~
\94 \82É
\93ü
\82ê
\82½
\8c³
\82Ì
\83t
\83@
\83C
\83\8b\82ð
\95\9c\8a\88\82³
\82¹
\82Ä
\82
\82¾
\82³
\82¢
\81B"+vbCR+vbLF+_
\r
669 "
\83R
\83s
\81[
\8c³
\81F"+FromTmpFilePath+vbCR+vbLF+ "
\83R
\83s
\81[
\90æ
\81F"+ToUpdateFilePath+vbCR+vbLF+ ed2
\r
671 If en <> 0 Then WScript.Echo "
\8dX
\90V
\82Í
\90¬
\8c÷
\82µ
\82Ü
\82µ
\82½
\82ª
\81A
\88ê
\8e\9e\83t
\83@
\83C
\83\8b\82Ì
\8dí
\8f\9c\82É
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½
\81B"+vbCR+vbLF+_
\r
672 "
\88ê
\8e\9e\83t
\83@
\83C
\83\8b\81F"+FromTmpFilePath+vbCR+vbLF+ "
\8dX
\90V
\8dÏ
\82Ý
\83t
\83@
\83C
\83\8b\81F"+ToUpdateFilePath+vbCR+vbLF+ ed
\r
678 '********************************************************************************
\r
680 '********************************************************************************
\r
681 Sub del( ByVal path )
\r
683 ' If path had Wild card
\r
684 If IsWildCard( path ) Then
\r
685 Dim folder, fname, fnames()
\r
687 ExpandWildcard path, F_File, folder, fnames
\r
688 For Each fname in fnames
\r
689 del g_fs.BuildPath( folder, fname )
\r
692 ExpandWildcard path, F_Folder, folder, fnames
\r
693 For Each fname in fnames
\r
694 del g_fs.BuildPath( folder, fname )
\r
697 ' If path was file or folder path
\r
700 If g_fs.FileExists( path ) Then
\r
701 chk_in_workfolder path
\r
702 g_fs.DeleteFile path
\r
703 ElseIf g_fs.FolderExists( path ) Then
\r
706 chk_in_workfolder path
\r
714 '********************************************************************************
\r
715 ' <<< [del_subfolder] >>>
\r
716 '********************************************************************************
\r
717 Sub del_subfolder( ByVal path )
\r
718 Dim folder, fname, fnames()
\r
720 ExpandWildcard path, F_File Or F_SubFolder, folder, fnames
\r
721 For Each fname in fnames
\r
722 del g_fs.BuildPath( folder, fname )
\r
725 ExpandWildcard path, F_Folder Or F_SubFolder, folder, fnames
\r
726 For Each fname in fnames
\r
727 del g_fs.BuildPath( folder, fname )
\r
733 '********************************************************************************
\r
734 ' <<< [del_to_trashbox] >>>
\r
735 '********************************************************************************
\r
736 Sub del_to_trashbox( ByVal path )
\r
737 Dim sh_ap, TrashBox, folder, item, fname
\r
738 Set sh_ap = CreateObject("Shell.Application")
\r
739 Const ssfBITBUCKET = 10
\r
741 path = g_fs.GetAbsolutePathName( path )
\r
742 fname = g_fs.GetFileName( path )
\r
743 Set folder = sh_ap.NameSpace( g_fs.GetParentFolderName( path ) )
\r
744 If folder is Nothing Then Exit Sub
\r
745 Set item = folder.Items.Item( fname )
\r
746 If item is Nothing Then Exit Sub
\r
748 Set TrashBox = sh_ap.NameSpace( ssfBITBUCKET )
\r
749 TrashBox.MoveHere item
\r
753 Set item = folder.Items.Item( fname )
\r
754 If item is Nothing Then Exit Do
\r
761 '********************************************************************************
\r
764 ' - return : count of made folder
\r
766 ' - This is able to make nested folder.
\r
767 '********************************************************************************
\r
768 Function mkdir( ByVal fo )
\r
769 Dim i, n, names(), fo2
\r
771 If g_fs.FolderExists( fo ) Then mkdir = 0 : Exit Function
\r
772 chk_in_workfolder fo
\r
775 fo2 = g_fs.GetAbsolutePathName( fo )
\r
777 If g_fs.FolderExists( fo2 ) Then Exit Do
\r
780 Redim Preserve names(n)
\r
781 names(n) = g_fs.GetFileName( fo2 )
\r
782 fo2 = g_fs.GetParentFolderName( fo2 )
\r
787 For n=n To 1 Step -1
\r
788 fo2 = g_fs.BuildPath( fo2, names(n) )
\r
789 g_fs.CreateFolder fo2
\r
796 '********************************************************************************
\r
798 '********************************************************************************
\r
799 Sub rmdir( ByVal path )
\r
800 Dim path2, iFolder, nFolder, fo, subf, f, file
\r
802 If Not g_fs.FolderExists( path ) Then Exit Sub
\r
804 chk_in_workfolder path
\r
809 If Right( path2, 1 ) = "\" Then path2 = Left( path2, Len( path2 ) - 1 )
\r
812 ReDim folderPathes(nFolder)
\r
813 folderPathes(nFolder) = path2
\r
817 While iFolder <= nFolder
\r
818 Set fo = g_fs.GetFolder( folderPathes(iFolder) )
\r
819 For Each subf in fo.SubFolders
\r
820 nFolder = nFolder + 1
\r
821 ReDim Preserve folderPathes(nFolder)
\r
822 folderPathes(nFolder) = subf.Path
\r
824 iFolder = iFolder + 1
\r
827 ' Remove read only attribute of all files in sub folders
\r
828 For iFolder = 1 To nFolder
\r
829 Set fo = g_fs.GetFolder( folderPathes(iFolder) )
\r
830 For Each f in fo.Files
\r
831 Set file = g_fs.GetFile( f.Path )
\r
832 file.Attributes = file.Attributes And Not ReadOnly
\r
838 On Error Resume Next
\r
839 g_fs.DeleteFolder( path )
\r
840 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
841 If en = E_WriteAccessDenied Then ed = "Denied to delete the folder: "+ path
\r
842 If en <> 0 Then Err.Raise en,,ed
\r
848 '********************************************************************************
\r
850 '********************************************************************************
\r
851 Function exist( ByVal path )
\r
852 If IsWildcard( path ) Then
\r
853 Dim folder, fnames()
\r
854 ExpandWildcard path, F_File, folder, fnames
\r
855 exist = UBound( fnames ) <> -1
\r
857 exist = ( g_fs.FileExists( path ) = True ) Or ( g_fs.FolderExists( path ) = True )
\r
863 '********************************************************************************
\r
864 ' <<< [fc] file compare as binary >>>
\r
866 ' - return : True=same, False=different
\r
867 '********************************************************************************
\r
868 Function fc( ByVal path_a, ByVal path_b )
\r
869 fc = fc_r( path_a, path_b, "nul" )
\r
874 '********************************************************************************
\r
875 ' <<< [fc_r] file compare as binary >>>
\r
877 ' - return : True=same, False=different
\r
878 '********************************************************************************
\r
879 Function fc_r( ByVal path_a, ByVal path_b, redirect_path )
\r
880 Dim echos_:Set echos_= New EchoOnOff
\r
883 cmdline = """" + g_vbslib_folder + "feq.exe"" """ + path_a + """ """ + path_b + """"
\r
885 If IsEmpty( redirect_path ) Then
\r
886 echo_c "fc """ + path_a + """ """ + path_b + """"
\r
887 chk_exist_in_lib "feq.exe"
\r
888 fc_r = g_sh.Run( cmdline, 7, TRUE )
\r
891 If redirect_path <> "nul" Then _
\r
892 echo_c "fc """ + path_a + """ """ + path_b + """ >> " + redirect_path
\r
893 chk_exist_in_lib "feq.exe"
\r
894 Set ex = g_sh.Exec( cmdline )
\r
895 redirect_path = g_sh.ExpandEnvironmentStrings( redirect_path )
\r
896 fc_r = WaitForFinishAndRedirect( ex, redirect_path )
\r
901 If fc_r And g_fs.FolderExists( path_a ) Then
\r
902 Dim folder, fnames_a(), fnames_b()
\r
905 ExpandWildcard path_a + "\*", F_Folder Or F_SubFolder, folder, fnames_a
\r
906 ExpandWildcard path_b + "\*", F_Folder Or F_SubFolder, folder, fnames_b
\r
907 If UBound(fnames_a) = UBound(fnames_b) Then
\r
908 For i=0 To UBound(fnames_a)
\r
909 If fnames_a(i) <> fnames_b(i) Then fc_r = False : Exit For
\r
917 ' fc_r = fc_r_imp( path_a, path_b, True, _
\r
918 ' g_fs.GetAbsolutePathName(path_a), redirect_path )
\r
923 'Function fc_r_imp( ByVal path_a, ByVal path_b, b_top, base_a, redirect_path )
\r
926 ' If g_fs.FileExists( path_a ) Then
\r
929 ' If Not g_fs.FileExists( path_b ) Then _
\r
930 ' echo_r "Not found (B)"+path_b, redirect_path : fc_r_imp=False : Exit Function
\r
932 ' r = RunProg( "fc.exe /B """ + path_a + """ """ + path_b + """", redirect_path )
\r
934 ' If b_top Then echo_r "same.", redirect_path
\r
936 ' If b_top Then echo_r "NOT same.", redirect_path _
\r
937 ' Else echo_r "NOT same in "+GetStepPath( path_a, base_a ), redirect_path
\r
939 ' fc_r_imp = ( r = 0 )
\r
942 ' ElseIf g_fs.FolderExists( path_a ) Then
\r
944 ' Dim foldersA, foldersB, folderA, folderB, foA, foB, step, f
\r
945 ' If Not g_fs.FolderExists( path_b ) Then _
\r
946 ' echo_r "Not found (B)"+g_fs.GetFileName(path_b)+" in "+GetStepPath( folderA, base_a ), redirect_path : fc_r_imp=False : Exit Function
\r
948 ' path_a = g_fs.GetAbsolutePathName( path_a )
\r
949 ' path_b = g_fs.GetAbsolutePathName( path_b )
\r
950 ' GetSubFolders foldersA, path_a
\r
951 ' GetSubFolders foldersB, path_b
\r
953 ' If UBound( foldersA ) <> UBound( foldersB ) Then _
\r
954 ' echo_r "NOT same count of folders in "+ GetStepPath( path_a, base_a ), redirect_path : fc_r_imp=False : Exit Function
\r
956 ' For Each folderA In foldersA
\r
957 ' step = Mid( folderA, Len( path_a ) + 1 )
\r
958 ' If step = "" Then
\r
961 ' folderB = g_fs.BuildPath( path_b, step )
\r
964 ' Set foA = g_fs.GetFolder( folderA )
\r
965 ' Set foB = g_fs.GetFolder( folderB )
\r
967 ' If foA.Files.Count <> foB.Files.Count Then _
\r
968 ' echo_r "NOT same count of files in "+ GetStepPath( folderA, base_a ), redirect_path : fc_r_imp=False : Exit Function
\r
970 ' For Each f In foA.Files
\r
971 ' If Not fc_r_imp( f.Path, folderB + Mid( f.Path, Len( folderA ) + 1 ), False, base_a, redirect_path ) Then
\r
972 ' fc_r_imp=False : Exit Function
\r
978 ' If r = 0 Then echo_r "same.", redirect_path
\r
982 ' echo_r "Not found (A)"+path_a, redirect_path : fc_r_imp=False : Exit Function
\r
988 '********************************************************************************
\r
989 ' <<< [find] find lines including keyword >>>
\r
990 '********************************************************************************
\r
991 Function find( ByVal keyword, ByVal path )
\r
993 Set f = g_fs.OpenTextFile( path )
\r
996 Do Until f.AtEndOfStream
\r
998 If InStr( line, keyword ) > 0 Then ret = ret + line
\r
1008 '********************************************************************************
\r
1009 ' <<< [find_c] find lines count including keyword >>>
\r
1010 '********************************************************************************
\r
1011 Function find_c( ByVal keyword, ByVal path )
\r
1013 Set f = g_fs.OpenTextFile( path )
\r
1016 Do Until f.AtEndOfStream
\r
1018 If InStr( line, keyword ) > 0 Then ret = ret + 1
\r
1028 '********************************************************************************
\r
1029 ' <<< [CreateFile] Create 1 line text file >>>
\r
1030 '********************************************************************************
\r
1031 Sub CreateFile( ByVal path, ByVal text )
\r
1034 chk_in_workfolder path
\r
1036 path = g_fs.GetAbsolutePathName( path )
\r
1037 folder = g_fs.GetParentFolderName( path )
\r
1040 Set t = g_fs.CreateTextFile( path, True, False )
\r
1047 '********************************************************************************
\r
1048 ' <<< [ReadFile] >>>
\r
1049 '********************************************************************************
\r
1050 Function ReadFile( Path )
\r
1055 On Error Resume Next
\r
1056 Set f = g_fs.OpenTextFile( Path )
\r
1057 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1058 If en = E_FileNotExist Then Exit Function
\r
1059 If en <> 0 Then Err.Raise en,,ed
\r
1061 ReadFile = ReadAll( f )
\r
1066 '********************************************************************************
\r
1067 ' <<< [OpenTextFile] >>>
\r
1068 '********************************************************************************
\r
1069 Function OpenTextFile( Path )
\r
1072 On Error Resume Next
\r
1073 Set OpenTextFile = g_fs.OpenTextFile( Path )
\r
1074 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1075 If en = E_FileNotExist Then Err.raise en,,ed+" : "+Path
\r
1076 If en <> 0 Then Err.Raise en,,ed
\r
1081 '********************************************************************************
\r
1082 ' <<< [ReadAll] >>>
\r
1083 '********************************************************************************
\r
1084 Function ReadAll( FileStream )
\r
1088 On Error Resume Next
\r
1089 ReadAll = FileStream.ReadAll
\r
1090 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1091 If en = E_EndOfFile Then en = 0
\r
1092 If en <> 0 Then Err.Raise en,,ed
\r
1097 '********************************************************************************
\r
1098 ' <<< [WriteVBSLibHeader] >>>
\r
1099 '********************************************************************************
\r
1100 Sub WriteVBSLibHeader( OutFileStream, Opt )
\r
1103 Set f = g_fs.OpenTextFile( WScript.ScriptFullName )
\r
1104 Do Until f.AtEndOfStream
\r
1108 If InStr( line, "g_CommandPrompt =" ) > 0 and not IsEmpty( Opt ) Then
\r
1109 If not IsEmpty( Opt.m_OverCommandPrompt ) Then
\r
1110 line = " g_CommandPrompt = " & Opt.m_OverCommandPrompt
\r
1113 If InStr( line, "main()" ) > 0 Then Exit Do
\r
1115 OutFileStream.WriteLine line
\r
1120 Class WriteVBSLibHeader_Option
\r
1121 Public m_OverCommandPrompt
\r
1126 '********************************************************************************
\r
1127 ' <<< [GetAbsPath] >>>
\r
1128 '********************************************************************************
\r
1129 Function GetAbsPath( StepPath, BasePath )
\r
1130 Dim i, ii, i3, sep_ch, path
\r
1133 '//=== sep_ch = separetor "\" or "/"
\r
1134 i = InStr( BasePath, "\" )
\r
1135 ii = InStr( BasePath, "/" )
\r
1138 If i > ii Then sep_ch = "/" Else sep_ch = "\"
\r
1143 If ii > 0 Then sep_ch = "/" Else sep_ch = "\"
\r
1147 '//=== Joint and Replace to sep_ch
\r
1148 If Right( BasePath, 1 ) = sep_ch Then
\r
1149 path = BasePath + StepPath
\r
1151 path = BasePath + sep_ch + StepPath
\r
1153 If sep_ch = "\" Then
\r
1154 path = Replace( path, "/", "\" )
\r
1156 path = Replace( path, "\", "/" )
\r
1160 '//=== Cut xxx\..\
\r
1162 i = InStr( path, sep_ch+".."+sep_ch )
\r
1163 If i = 0 Then Exit Do
\r
1166 ii = InStr( i3+1, path, sep_ch )
\r
1167 If ii = 0 Then Exit Do
\r
1169 If i3 = 0 and i = 1 Then Exit Do
\r
1170 path = Left( path, i3 ) + Mid( path, i+4 )
\r
1182 '********************************************************************************
\r
1183 ' <<< [GetStepPath] >>>
\r
1184 ' - AbsPath, BasePath, (return) as string
\r
1185 '********************************************************************************
\r
1188 'Set g_fs = CreateObject( "Scripting.FileSystemObject" )
\r
1189 'If GetStepPath( "C:\folder\file.txt", "c:\folder" ) <> "file.txt" Then MsgBox "ERROR!"
\r
1190 'If GetStepPath( "C:\folder\file.txt", "c:\folder\" ) <> "file.txt" Then MsgBox "ERROR!"
\r
1191 'If GetStepPath( "C:\folder\file.txt", "c:\folder\sub" ) <> "..\file.txt" Then MsgBox "ERROR!"
\r
1192 'If GetStepPath( "C:\folder\file.txt", "c:\" ) <> "folder\file.txt" Then MsgBox "ERROR!"
\r
1193 'If GetStepPath( "C:\folder", "c:\folder" ) <> "." Then MsgBox "ERROR!"
\r
1194 'If GetStepPath( "http://www.a.com/folder/file.txt", "http://www.a.com/folder/" ) <> "file.txt" Then MsgBox "ERROR!"
\r
1195 'If GetStepPath( "http://www.a.com/folder/file.txt", "http://www.a.com/" ) <> "folder/file.txt" Then MsgBox "ERROR!"
\r
1199 Function GetStepPath( AbsPath, BasePath )
\r
1200 Dim AbsPathU, BasePathU, path, sep_ch, i, ii
\r
1202 AbsPathU = UCase(AbsPath)
\r
1203 BasePathU = UCase(BasePath)
\r
1206 '// sep_ch = separetor "\" or "/"
\r
1207 i = InStr( AbsPath, "\" )
\r
1208 ii = InStr( AbsPath, "/" )
\r
1211 If i > ii Then sep_ch = "/" Else sep_ch = "\"
\r
1216 If ii > 0 Then sep_ch = "/" Else sep_ch = "\"
\r
1220 '// path = common parent folder path
\r
1222 If Right(BasePathU,1) = sep_ch Then path = Left(BasePathU,Len(BasePathU)-1)
\r
1224 If path = Left( AbsPathU, Len(path) ) Then Exit Do
\r
1225 path = g_fs.GetParentFolderName( path )
\r
1227 If path = "" Then GetStepPath = AbsPath : Exit Function
\r
1230 '// GetStepPath = step path without ..\
\r
1231 GetStepPath = Mid( AbsPath, Len(path) + 2 )
\r
1234 '// GetStepPath: Add "..\"
\r
1235 path = Mid( BasePath, Len(path) + 2 )
\r
1237 If path = "" Then Exit Do
\r
1238 path = g_fs.GetParentFolderName( path )
\r
1239 GetStepPath = ".." + sep_ch + GetStepPath
\r
1242 If GetStepPath = "" Then GetStepPath = "."
\r
1247 '********************************************************************************
\r
1248 ' <<< [IsWildcard] >>>
\r
1249 '********************************************************************************
\r
1250 Function IsWildcard( ByVal path )
\r
1251 IsWildcard = InStr( path, "?" ) <> 0 Or InStr( path, "*" ) <> 0
\r
1256 '********************************************************************************
\r
1257 ' <<< [ExpandWildcard] >>>
\r
1258 '********************************************************************************
\r
1259 Sub ExpandWildcard( ByVal wildcard_path, flags, folder, fnames )
\r
1262 folder = g_fs.GetParentFolderName( g_fs.GetAbsolutePathName( wildcard_path ) )
\r
1264 Set re = CreateObject("VBScript.RegExp")
\r
1266 s = g_fs.GetFileName( wildcard_path )
\r
1267 re.Pattern = "\\" : s = re.Replace( s, "\\" )
\r
1268 re.Pattern = "\." : s = re.Replace( s, "\." )
\r
1269 re.Pattern = "\$" : s = re.Replace( s, "\$" )
\r
1270 re.Pattern = "\^" : s = re.Replace( s, "\^" )
\r
1271 re.Pattern = "\{" : s = re.Replace( s, "\{" )
\r
1272 re.Pattern = "\}" : s = re.Replace( s, "\}" )
\r
1273 re.Pattern = "\[" : s = re.Replace( s, "\[" )
\r
1274 re.Pattern = "\]" : s = re.Replace( s, "\]" )
\r
1275 re.Pattern = "\(" : s = re.Replace( s, "\(" )
\r
1276 re.Pattern = "\)" : s = re.Replace( s, "\)" )
\r
1277 re.Pattern = "\|" : s = re.Replace( s, "\|" )
\r
1278 re.Pattern = "\+" : s = re.Replace( s, "\+" )
\r
1279 re.Pattern = "\*" : s = re.Replace( s, ".*" )
\r
1280 re.Pattern = "\?" : s = re.Replace( s, "." )
\r
1282 re.Pattern = "^" + s
\r
1283 If Left( re.Pattern, 3 ) = "^.*" Then re.Pattern = Mid( re.Pattern, 4 )
\r
1285 ReDim fnames( -1 )
\r
1287 ExpandWildcard_sub re, flags, folder, "", fnames
\r
1291 Sub ExpandWildcard_sub( re, flags, folder, step_folder, fnames )
\r
1294 Set fo = g_fs.GetFolder( folder )
\r
1295 If flags And F_File Then
\r
1296 For Each f in fo.Files
\r
1297 If re.Test( f.Name ) Then
\r
1298 ReDim Preserve fnames( UBound(fnames) + 1 )
\r
1299 fnames( UBound(fnames) ) = step_folder + f.Name
\r
1303 If flags And F_Folder Then
\r
1304 For Each f in fo.SubFolders
\r
1305 If re.Test( f.Name ) Then
\r
1306 ReDim Preserve fnames( UBound(fnames) + 1 )
\r
1307 fnames( UBound(fnames) ) = step_folder + f.Name
\r
1312 If flags And F_SubFolder Then
\r
1313 For Each f in fo.SubFolders
\r
1314 ExpandWildcard_sub re, flags, f.Path, step_folder + f.Name + "\", fnames
\r
1321 '********************************************************************************
\r
1322 ' <<< [GetSubFolders] >>>
\r
1324 ' - folders : (out) array of folder pathes
\r
1325 ' - path : base folder path
\r
1326 '********************************************************************************
\r
1327 Sub GetSubFolders( folders, ByVal path )
\r
1329 EnumSubFolders folders, g_fs.GetFolder( path )
\r
1332 Sub EnumSubFolders( folders, fo )
\r
1335 ReDim Preserve folders( UBound(folders) + 1 )
\r
1336 folders( UBound(folders) ) = fo.Path
\r
1338 For Each subfo in fo.SubFolders
\r
1339 EnumSubFolders folders, subfo
\r
1345 '********************************************************************************
\r
1346 ' <<< [RemoveWildcard] >>>
\r
1347 '********************************************************************************
\r
1348 Sub RemoveWildcard( WildCard, fnames )
\r
1349 Dim s, path, fname, i, n, wc, wc_len
\r
1352 '//=== check by with wildcard
\r
1353 If Left( WildCard, 1 ) = "*" Then
\r
1354 wc = LCase( Mid( WildCard, 2 ) ) : wc_len = Len( wc )
\r
1355 n = UBound( fnames )
\r
1359 fname = g_fs.GetFileName( path )
\r
1360 If LCase( Right( fname, wc_len ) ) = wc Then fnames(i) = Empty : Exit Do
\r
1361 path = g_fs.GetParentFolderName( path )
\r
1362 If path = "" Then Exit Do
\r
1367 '//=== check by no wildcard
\r
1369 wc = LCase( WildCard )
\r
1370 n = UBound( fnames )
\r
1374 fname = g_fs.GetFileName( path )
\r
1375 If LCase( fname ) = wc Then fnames(i) = Empty : Exit Do
\r
1376 path = g_fs.GetParentFolderName( path )
\r
1377 If path = "" Then Exit Do
\r
1383 '//=== shrink the array
\r
1385 For i = 0 To UBound( fnames )
\r
1386 If not IsEmpty( fnames(i) ) Then fnames(n) = fnames(i) : n = n + 1
\r
1388 Redim Preserve fnames( n - 1 )
\r
1393 '********************************************************************************
\r
1394 ' <<< [MeltCSV] >>>
\r
1395 '********************************************************************************
\r
1396 Function MeltCSV( Line, in_out_Start )
\r
1401 '//=== Skip space character
\r
1403 c = Mid( Line, i, 1 )
\r
1404 If c<>" " and c<>vbTab Then Exit Do
\r
1410 '//=== If enclosed by " "
\r
1414 c = Mid( Line, i, 1 )
\r
1415 If c = "" Then Exit Do
\r
1418 c = Mid( Line, i, 1 )
\r
1419 If c = """" Then s = s + c Else Exit Do
\r
1428 If c = "" Then in_out_Start = 0 : Exit Function
\r
1429 If c = "," Then in_out_Start = i+1 : Exit Function
\r
1431 c = Mid( Line, i, 1 )
\r
1435 '//=== If no value
\r
1437 in_out_Start = i+1 : Exit Function
\r
1439 in_out_Start = 0 : Exit Function
\r
1442 '//=== If NOT enclosed by " "
\r
1445 If c = "" or c = "," Then Exit Do
\r
1448 c = Mid( Line, i, 1 )
\r
1451 MeltCSV = Trim( s )
\r
1453 If c = "" Then in_out_Start = 0 : Exit Function
\r
1454 If c = "," Then in_out_Start = i+1 : Exit Function
\r
1460 '*-------------------------------------------------------------------------*
\r
1461 '*
\81\9f<<<<
\8aÖ
\90\94\83R
\81[
\83\8b\82Æ include >>>>
\r
1462 '*-------------------------------------------------------------------------*
\r
1466 '********************************************************************************
\r
1467 ' <<< [call_vbs] >>>
\r
1468 '********************************************************************************
\r
1469 Function call_vbs( path, func, param )
\r
1470 call_vbs = call_vbs_t( path, func, param )
\r
1475 '*-------------------------------------------------------------------------*
\r
1476 '*
\81\9f<<<<
\83v
\83\8d\83Z
\83X >>>>
\r
1477 '*-------------------------------------------------------------------------*
\r
1481 '********************************************************************************
\r
1482 ' <<< [env] Expand environment strings >>>
\r
1483 '********************************************************************************
\r
1485 env = g_sh.ExpandEnvironmentStrings( s )
\r
1490 '********************************************************************************
\r
1491 ' <<< [start] >>>
\r
1492 '********************************************************************************
\r
1493 Sub start( cmdline )
\r
1495 cmdline = g_sh.ExpandEnvironmentStrings( cmdline )
\r
1496 g_sh.Run cmdline,, FALSE
\r
1499 '********************************************************************************
\r
1500 ' <<< [RunProg] >>>
\r
1501 '********************************************************************************
\r
1502 Function RunProg( ByVal cmdline, stdout_stderr_redirect )
\r
1505 '// Set debug mode
\r
1506 If stdout_stderr_redirect = "_debug" Then
\r
1507 dbg_cmd = "cmd /K " : stdout_stderr_redirect = ""
\r
1513 '// Echo command line
\r
1514 If stdout_stderr_redirect = "" Then
\r
1517 echo_c cmdline+" >> """+stdout_stderr_redirect+""""
\r
1521 '// Create new process
\r
1522 cmdline = g_sh.ExpandEnvironmentStrings( cmdline )
\r
1525 Set ex = g_sh.Exec( cmdline )
\r
1526 stdout_stderr_redirect = g_sh.ExpandEnvironmentStrings( stdout_stderr_redirect )
\r
1527 RunProg = WaitForFinishAndRedirect( ex, stdout_stderr_redirect )
\r
1532 '********************************************************************************
\r
1533 ' <<< [WaitForFinishAndRedirect] >>>
\r
1534 '********************************************************************************
\r
1535 Function WaitForFinishAndRedirect( ex, path )
\r
1538 If path <> "" and path <> "nul" Then _
\r
1539 Set f = g_fs.OpenTextFile( path, 8, True, False )
\r
1541 Do While ex.Status = 0
\r
1544 Do Until ex.StdOut.AtEndOfStream : echo ex.StdOut.ReadLine : Loop
\r
1545 Do Until ex.StdErr.AtEndOfStream : echo ex.StdErr.ReadLine : Loop
\r
1546 ElseIf path = "nul" Then
\r
1547 Do Until ex.StdOut.AtEndOfStream : ex.StdOut.ReadLine : Loop
\r
1548 Do Until ex.StdErr.AtEndOfStream : ex.StdErr.ReadLine : Loop
\r
1550 Do Until ex.StdOut.AtEndOfStream : f.WriteLine ex.StdOut.ReadLine : Loop
\r
1551 Do Until ex.StdErr.AtEndOfStream : f.WriteLine ex.StdErr.ReadLine : Loop
\r
1556 Do Until ex.StdOut.AtEndOfStream : echo ex.StdOut.ReadLine : Loop
\r
1557 Do Until ex.StdErr.AtEndOfStream : echo ex.StdErr.ReadLine : Loop
\r
1558 ElseIf path = "nul" Then
\r
1559 Do Until ex.StdOut.AtEndOfStream : ex.StdOut.ReadLine : Loop
\r
1560 Do Until ex.StdErr.AtEndOfStream : ex.StdErr.ReadLine : Loop
\r
1562 Do Until ex.StdOut.AtEndOfStream : f.WriteLine ex.StdOut.ReadLine : Loop
\r
1563 Do Until ex.StdErr.AtEndOfStream : f.WriteLine ex.StdErr.ReadLine : Loop
\r
1565 WaitForFinishAndRedirect = ex.ExitCode
\r
1570 '********************************************************************************
\r
1571 ' <<< [ArgumentExist] >>>
\r
1572 '********************************************************************************
\r
1573 Function ArgumentExist( name )
\r
1575 For Each key in WScript.Arguments.Named
\r
1576 If key = name Then ArgumentExist = True : Exit Function
\r
1578 ArgumentExist = False
\r
1583 '*-------------------------------------------------------------------------*
\r
1584 '*
\81\9f<<<<
\91Ò
\82¿
\81A
\90§
\8cä >>>>
\r
1585 '*-------------------------------------------------------------------------*
\r
1589 '********************************************************************************
\r
1590 ' <<< [Sleep] >>>
\r
1591 '********************************************************************************
\r
1592 Sub Sleep( ByVal msec )
\r
1593 WScript.Sleep msec
\r
1598 '********************************************************************************
\r
1599 ' <<< [WaitForFile] Wait for make the file >>>
\r
1600 '********************************************************************************
\r
1601 Sub WaitForFile( ByVal path )
\r
1602 While g_fs.FileExists( path ) = False
\r
1603 WScript.Sleep 1000
\r
1609 '*-------------------------------------------------------------------------*
\r
1610 '*
\81\9f<<<<
\94z
\97ñ
\81A
\83R
\83\8c\83N
\83V
\83\87\83\93 >>>>
\r
1611 '*-------------------------------------------------------------------------*
\r
1615 '********************************************************************************
\r
1616 ' <<< [QuickSort_fromDic] >>>
\r
1617 'dic as Scripting.Dictionary
\r
1618 'out_arr as [out] object array
\r
1619 '********************************************************************************
\r
1620 Sub QuickSort_fromDic( dic, out_arr, compare_func, param )
\r
1621 Dim i, i_last, elem
\r
1622 i_last = dic.Count - 1
\r
1623 Redim out_arr( i_last )
\r
1626 For Each elem In dic.Items
\r
1627 Set out_arr(i) = elem
\r
1631 QuickSort out_arr, 0, i_last, compare_func, param
\r
1636 '********************************************************************************
\r
1637 ' <<< [QuickSort] >>>
\r
1638 '********************************************************************************
\r
1639 Sub QuickSort( arr, i_left, i_right, compare_func, param )
\r
1640 Dim pivot, i_pivot, i_big, i_small, sw
\r
1642 If i_left >= i_right Then Exit Sub ' rule-b'
\r
1644 i_pivot = ( i_left + i_right ) \ 2
\r
1645 Set pivot = arr( i_pivot )
\r
1649 ' Dim i, sym, value
\r
1650 ' echo "QuickSort start ----------------------"
\r
1651 ' For i = i_left To i_right
\r
1652 ' QuickSort_Debug_getSym arr, i, sym, value
\r
1653 ' If i = i_pivot Then value = value & " (pivot)"
\r
1654 ' echo "(" & i & ") " & sym & " = " & value
\r
1659 i_big = i_left : i_small = i_right
\r
1661 '// Set i_big on smaller than pivot
\r
1663 If compare_func( arr(i_big), pivot, param ) >= 0 Then Exit Do
\r
1667 '// Set i_small on equal or bigger than pivot
\r
1669 If i_small < i_pivot and i_small < i_big Then
\r
1670 If i_big < i_pivot Then i_small = i_pivot : Exit Do _
\r
1671 Else Exit Sub ' rule-c
\r
1673 If compare_func( arr(i_small), pivot, param ) < 0 Then Exit Do
\r
1674 i_small = i_small - 1
\r
1678 If i_big < i_small Then ' rule-a
\r
1679 Set sw = arr(i_big) : Set arr(i_big) = arr(i_small) : Set arr(i_small) = sw
\r
1680 If i_big = i_pivot Then i_pivot = i_small
\r
1681 If i_small = i_pivot Then i_big = i_big + 1 : Exit Do ' rule-c'
\r
1689 ' echo "QuickSort middle ----------------------"
\r
1690 ' For i = i_left To i_right
\r
1691 ' QuickSort_Debug_getSym arr, i, sym, value
\r
1692 ' If i = i_big-1 Then value = value & " (i_big-1)"
\r
1693 ' If i = i_big Then value = value & " (i_big)"
\r
1694 ' echo "(" & i & ") " & sym & " = " & value
\r
1698 QuickSort arr, i_left, i_big-1, compare_func, param ' rule-b
\r
1699 QuickSort arr, i_big, i_right, compare_func, param ' rule-b
\r
1703 ' echo "QuickSort end ----------------------"
\r
1704 ' For i = i_left To i_right
\r
1705 ' QuickSort_Debug_getSym arr, i, sym, value
\r
1706 ' echo "(" & i & ") " & sym & " = " & value
\r
1711 Sub QuickSort_Debug_getSym( Arr, Index, out_Symbol, out_Value )
\r
1712 out_Symbol = Index
\r
1713 out_Value = Arr(Index).id
\r
1718 '********************************************************************************
\r
1719 ' <<< [ShakerSort_fromDic] >>>
\r
1720 'dic as Scripting.Dictionary
\r
1721 'out_arr as [out] object array
\r
1722 '********************************************************************************
\r
1723 Sub ShakerSort_fromDic( dic, out_arr, sign, compare_func, param )
\r
1724 Dim i, i_last, elem
\r
1725 i_last = dic.Count - 1
\r
1726 Redim out_arr( i_last )
\r
1730 For Each elem In dic.Items
\r
1731 Set out_arr(i) = elem
\r
1736 For Each elem In dic.Items
\r
1737 Set out_arr(i) = elem
\r
1742 ShakerSort out_arr, 0, i_last, compare_func, param
\r
1747 '********************************************************************************
\r
1748 ' <<< [ShakerSort] >>>
\r
1749 '********************************************************************************
\r
1750 Sub ShakerSort( arr, i_left, i_right, compare_func, param )
\r
1755 For i=i_left+1 To i_right
\r
1756 If compare_func( arr(i-1), arr(i), param ) > 0 Then
\r
1757 Set sw = arr(i-1) : Set arr(i-1) = arr(i) : Set arr(i) = sw
\r
1761 If i_swap = i_left+1 Then Exit Do
\r
1762 i_right = i_swap-1
\r
1764 i_swap = i_right-1
\r
1765 For i=i_right-1 To i_left Step -1
\r
1766 If compare_func( arr(i), arr(i+1), param ) > 0 Then
\r
1767 Set sw = arr(i) : Set arr(i) = arr(i+1) : Set arr(i+1) = sw
\r
1771 If i_swap = i_right-1 Then Exit Do
\r
1777 '********************************************************************************
\r
1778 ' <<< [CInt2] >>>
\r
1780 '********************************************************************************
\r
1781 Function CInt2( v )
\r
1784 On Error Resume Next
\r
1786 en = Err.Number : ed = Err.Description : On Error GoTo 0
\r
1787 If en = 13 Then '// if sym is not number
\r
1789 ElseIf en <> 0 Then Err.Raise en,,ed End If
\r
1794 '*-------------------------------------------------------------------------*
\r
1795 '* <<<< [ArrayClass] Class >>>> */
\r
1796 '*-------------------------------------------------------------------------*
\r
1801 Private Sub Class_Initialize
\r
1802 ReDim m_Array( -1 )
\r
1805 Public Sub ToEmpty()
\r
1806 ReDim m_Array( -1 )
\r
1809 Public Sub Add( elem )
\r
1813 Public Sub Push( elem )
\r
1814 ReDim Preserve m_Array( UBound(m_Array) + 1 )
\r
1815 If IsObject( elem ) Then
\r
1816 Set m_Array( UBound(m_Array) ) = elem
\r
1818 m_Array( UBound(m_Array) ) = elem
\r
1822 Public Function Pop()
\r
1823 If IsObject( m_Array( UBound(m_Array) ) ) Then
\r
1824 Set Pop = m_Array( UBound(m_Array) )
\r
1826 Pop = m_Array( UBound(m_Array) )
\r
1828 ReDim Preserve m_Array( UBound(m_Array) - 1 )
\r
1831 Public Function Count()
\r
1832 Count = UBound(m_Array) + 1
\r
1837 WScript.Echo "count = " & Count
\r
1838 For Each i In m_Array
\r
1839 If IsObject( i ) Then
\r
1840 WScript.Echo "Class " & TypeName( i )
\r
1841 On Error Resume Next
\r
1845 If e <> 0 And e <> 438 Then Err.Raise e
\r
1847 WScript.Echo "each = " & i
\r
1855 '*-------------------------------------------------------------------------*
\r
1856 '* <<<< [ArrayDictionary] Class >>>> */
\r
1857 '*-------------------------------------------------------------------------*
\r
1859 class ArrayDictionary
\r
1863 Private Sub Class_Initialize
\r
1864 Set m_Dic = CreateObject("Scripting.Dictionary")
\r
1867 Public Sub ToEmpty
\r
1871 Public Sub Add( key, item )
\r
1874 If m_Dic.Exists( key ) Then
\r
1875 m_Dic.Item( key ).Add item
\r
1877 Set dic_item = New ArrayClass
\r
1879 m_Dic.Add key, dic_item
\r
1883 Public Function Count
\r
1886 For Each i in m_Dic.Items()
\r
1887 Count = Count + i.Count
\r
1894 WScript.Echo "--- ArrayDictionary ------------------------------"
\r
1895 WScript.Echo "key count = " & m_Dic.Count
\r
1897 WScript.Echo "item count = " & Count
\r
1899 For Each i in m_Dic.Keys()
\r
1900 WScript.Echo "key=""" & i & """"
\r
1901 m_Dic.Item(i).Echo
\r
1910 '*-------------------------------------------------------------------------*
\r
1911 '*
\81\9f<<<<
\83G
\83\89\81[
\8f\88\97\9d \81iErr2
\81j >>>>
\r
1912 '*-------------------------------------------------------------------------*
\r
1916 '********************************************************************************
\r
1917 ' <<< [Finish] >>>
\r
1918 '********************************************************************************
\r
1925 '********************************************************************************
\r
1926 ' <<< [Error] >>>
\r
1927 '********************************************************************************
\r
1930 WScript.Echo "[ERROR] Unknown"
\r
1937 '********************************************************************************
\r
1939 '********************************************************************************
\r
1942 Public Number ' Err.Number
\r
1943 Public num ' Err.Number
\r
1944 Public Description ' Err.Description (Error Message)
\r
1945 Public desc ' Err.Description (Error Message)
\r
1946 Public Source ' Err.Source
\r
1947 Public ErrID ' count of (num <> 0) in each first Copy after Clear
\r
1948 Public RaiseID ' count of (num <> 0) in Copy
\r
1949 Public BreakErrID ' as integer
\r
1950 Public BreakRaiseID ' as integer
\r
1952 Private Sub Class_Initialize
\r
1953 num = 0 : Description = "" : ErrID = 0 : RaiseID = 0
\r
1956 Public Sub OnSuccessFinish
\r
1957 If num <> 0 Then Err.Raise num, Source, Description
\r
1958 If Err.Number <> 0 Then echo GetErrStr( Err.Number, Err.Description, Err.Source )
\r
1961 Public Sub Copy( err )
\r
1962 Me.Number = err.Number
\r
1963 Me.num = err.Number
\r
1964 Me.Description = err.Description
\r
1965 Me.desc = err.Description
\r
1966 Me.Source = err.Source
\r
1967 if Me.num <> 0 Then Me.RaiseID = Me.RaiseID + 1 : if Me.RaiseID = 1 Then Me.ErrID = Me.ErrID + 1
\r
1971 Public Function Value
\r
1972 Value = GetErrStr( num, Description, Source )
\r
1975 Public Sub OverRaise( e_num, e_desc )
\r
1977 Description = e_desc
\r
1985 Err.Raise num, Source, Description
\r
1990 num = 0 : Description = "" : RaiseID = 0
\r
1996 '********************************************************************************
\r
1997 ' <<< [Raise] >>>
\r
1998 '********************************************************************************
\r
1999 Sub Raise( ErrNum, Description )
\r
2000 g_Err2.num = ErrNum
\r
2001 g_Err2.Source = ""
\r
2002 g_Err2.Description = Description
\r
2003 g_Err2.RaiseID = g_Err2.RaiseID + 1 : if g_Err2.RaiseID = 1 Then g_Err2.ErrID = g_Err2.ErrID + 1
\r
2004 If g_debug Then echo "ErrID = " & g_Err2.ErrID & ", RaiseID = " & g_Err2.RaiseID
\r
2006 Err.raise g_Err2.num, g_Err2.Source, g_Err2.Description
\r
2011 '********************************************************************************
\r
2012 ' <<< [SetErrBreak] >>>
\r
2013 '********************************************************************************
\r
2014 Sub SetErrBreak( ErrID, RaiseID )
\r
2015 g_Err2.BreakErrID = ErrID
\r
2016 g_Err2.BreakRaiseID = RaiseID
\r
2021 '********************************************************************************
\r
2022 ' <<< [BreakByID] >>>
\r
2023 '********************************************************************************
\r
2025 If g_Err2.ErrID = g_Err2.BreakErrID And g_Err2.RaiseID >= g_Err2.BreakRaiseID Then
\r
2026 echo "ErrID = " & g_Err2.ErrID & ", RaiseID = " & g_Err2.RaiseID
\r
2033 '********************************************************************************
\r
2034 ' <<< [NestPos] >>>
\r
2035 '********************************************************************************
\r
2037 Public m_HereArr()
\r
2039 Private Sub Class_Initialize '
\83R
\83\93\83X
\83g
\83\89\83N
\83^
\r
2040 Redim m_HereArr(0)
\r
2044 Public Function GetPos( arr )
\r
2046 u = UBound( m_HereArr )
\r
2048 Redim Preserve arr(u-1)
\r
2051 arr(i) = m_HereArr(i)
\r
2055 Public Sub OnBlockStart
\r
2057 u = UBound( m_HereArr )
\r
2058 m_HereArr(u) = m_HereArr(u) + 1
\r
2059 Redim Preserve m_HereArr(u+1)
\r
2060 m_HereArr(u+1) = 0
\r
2063 Public Sub OnBlockEnd
\r
2064 Redim Preserve m_HereArr( UBound( m_HereArr ) - 1 )
\r
2070 '********************************************************************************
\r
2071 ' <<< [GetErrStr] >>>
\r
2072 '********************************************************************************
\r
2073 Function GetErrStr( en, ed, es )
\r
2075 GetErrStr = "no error"
\r
2078 If en > 0 And en <= &h7FFF Then n = &h800A0000 + en Else n = en
\r
2079 GetErrStr = "[ERROR] " & Hex(n) & " " & ed & " " & es
\r
2085 '********************************************************************************
\r
2086 ' <<< [TryStart] >>>
\r
2087 '********************************************************************************
\r
2088 Function TryStart( e )
\r
2091 If e.ErrID >= e.BreakErrID - 1 Then
\r
2103 '********************************************************************************
\r
2104 ' <<< [Trying] >>>
\r
2105 '********************************************************************************
\r
2107 Trying = (Err.Number=0)
\r
2112 '********************************************************************************
\r
2113 ' <<< [TryEnd] >>>
\r
2114 '********************************************************************************
\r
2116 ' Do not have parameters.
\r
2117 ' Because "If TryEnd(e) Then On Error Goto 0" cannot get error, if e is not Dim.
\r
2119 If Err.Number <> 0 Then g_Err2.Copy Err
\r
2120 If g_debug = 1 Then TryEnd = False Else TryEnd = True
\r
2125 '********************************************************************************
\r
2126 ' <<< [chk_exist_in_lib] >>>
\r
2128 ' - If there is not path in vbslib folder, raise error of E_FileNotExist.
\r
2129 '********************************************************************************
\r
2130 Sub chk_exist_in_lib( ByVal path )
\r
2131 If not exist( g_vbslib_folder + path ) Then Err.Raise E_FileNotExist,, _
\r
2132 "Not found """ + g_vbslib_folder + path + """"
\r