-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtools_isXXX.bat
More file actions
167 lines (146 loc) · 7.31 KB
/
tools_isXXX.bat
File metadata and controls
167 lines (146 loc) · 7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
::Author : Shen Xiaolong((xlshen@126.com))
::Copyright : free use,modify,spread, but MUST include this original two line information(Author and Copyright).
::@set _Echo=1
::set _Stack=%~nx0
@if {"%_Echo%"}=={"1"} ( @echo on ) else ( @echo off )
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo. & @echo [+++++ %~nx0] commandLine: %0 %*
where "%~nx0" 1>nul 2>nul || set "path=%~dp0;%path%"
if {%1}=={} call :Test NoOutput & goto End
call :%~1 %2 %3 %4 %5 %6 %7 %8 %9
goto End
::[DOS_API:Help]display help information
:Help
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call tools_miscellaneous.bat DisplayHelp "%~f0"
goto :eof
::[DOS_API:Test] Test DOS API in this script file
:Test
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
@echo [%~nx0] Run test case [%0 %*]
echo.
echo test call :Help
call :Help
echo.
echo.
echo test call :isNumber 2345 bNumber
call :isNumber 2345 bNumber
if {"%bNumber%"}=={"1"} echo test OK. bNumber=%bNumber%
if not {"%bNumber%"}=={"1"} call tools_message.bat errorMsg "Fails to test isNumber 2345"
echo.
echo test call :isNumber 23gg45 bNumber
call :isNumber 23gg45 bNumber
if {"%bNumber%"}=={"0"} echo test OK. bNumber=%bNumber%
if not {"%bNumber%"}=={"0"} call tools_message.bat errorMsg "Fails to test isNumber 23gg45"
echo.
echo test call :isNumber 2345gn bNumber
call :isNumber 2345gn bNumber
if {"%bNumber%"}=={"0"} echo test OK. bNumber=%bNumber%
if not {"%bNumber%"}=={"0"} call tools_message.bat errorMsg "Fails to test isNumber 2345gn"
echo.
echo test call :isNumber abdf bNumber
call :isNumber abdf bNumber
if {"%bNumber%"}=={"0"} echo test OK. bNumber=%bNumber%
if not {"%bNumber%"}=={"0"} call tools_message.bat errorMsg "Fails to test isNumber abdf"
echo.
echo test call :isUnicodeFile "%~fs0" bUnicode
call :isUnicodeFile "%~fs0" bUnicode
if {"%bUnicode%"}=={"0"} echo test OK. bUnicode=%bUnicode%
if not {"%bUnicode%"}=={"0"} call tools_message.bat errorMsg "Fails to test isUnicodeFile '%~fs0'"
echo.
echo test call :isAsciiFile "%~fs0" bAscii
call :isAsciiFile "%~fs0" bAscii
if {"%bAscii%"}=={"1"} echo test OK. bAscii=%bAscii%
if not {"%bAscii%"}=={"1"} call tools_message.bat errorMsg "Fails to test isAsciiFile '%~fs0'"
echo.
echo test call :isEmptyFile "%~fs0" bEmptyFile
call :isEmptyFile "%~fs0" bEmptyFile
if {"%bEmptyFile%"}=={"0"} echo test OK. bEmptyFile=%bEmptyFile%
if not {"%bEmptyFile%"}=={"0"} call tools_message.bat errorMsg "Fails to test isEmptyFile '%~fs0'"
echo.
echo test call :isEmptyFile "%~fs0.txt" bEmptyFile
call :isEmptyFile "%~fs0.txt" bEmptyFile
if {"%bEmptyFile%"}=={"1"} echo test OK. bEmptyFile=%bEmptyFile%
if not {"%bEmptyFile%"}=={"1"} call tools_message.bat errorMsg "Fails to test isEmptyFile '%~fs0.txt'"
echo.
echo test call :isEmptyFolder "%~dp0" bEmptyFolder
call :isEmptyFolder "%~dp0" bEmptyFolder
if {"%bEmptyFolder%"}=={"0"} echo test OK. bEmptyFolder=%bEmptyFolder%
if not {"%bEmptyFolder%"}=={"0"} call tools_message.bat errorMsg "Fails to test isEmptyFolder '%~dp0'"
echo.
echo test call :isEmptyFolder "%~dp0tt" bEmptyFolder
call :isEmptyFolder "%~dp0tt" bEmptyFolder
if {"%bEmptyFolder%"}=={"1"} echo test OK. bEmptyFolder=%bEmptyFolder%
if not {"%bEmptyFolder%"}=={"1"} call tools_message.bat errorMsg "Fails to test isEmptyFolder '%~dp0tt'"
echo.
echo test call :isSameFile "%~fs0" "%~fs0" bSameFile
call :isSameFile "%~fs0" "%~fs0" bSameFile
if {"%bSameFile%"}=={"1"} echo test OK. bSameFile=%bSameFile%
if not {"%bSameFile%"}=={"1"} call tools_message.bat errorMsg "Fails to test isSameFile '%~nx0' and '%~nx0'"
echo.
echo test call :isSameFile "%~fs0" "%~dp0tools_txtFile.bat" bSameFile
call :isSameFile "%~fs0" "%~dp0tools_txtFile.bat" bSameFile
if {"%bSameFile%"}=={"0"} echo test OK. bSameFile=%bSameFile%
if not {"%bSameFile%"}=={"0"} call tools_message.bat errorMsg "Fails to test isSameFile '%~nx0' and 'tools_txtFile.bat'"
goto :eof
::[DOS_API:isNumber]test whether first parameter is number , result is stored in 2nd parameter
::call e.g : call :isNumber 3454 bNumber //set bNumber=1
:: call :isNumber 34gd bNumber //set bNumber=0
:isNumber
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set %~2=0
call SET "_tmpNumTest="
for /f "delims=0123456789" %%i in ("%~1") do set _tmpNumTest=%%i
if not defined _tmpNumTest set "%~2=1"
goto :eof
::[DOS_API:isEmptyFile]test whether file is empty , result is stored in 2nd parameter
::call e.g : call :isEmptyFile filePath bEMpty
:: call :isEmptyFile d:\temp\myFil.txt bEMpty //set bEMpty=0
:isEmptyFile
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set %~2=1
if not exist "%~1" goto :eof
if not {" %~z1"}=={"0"} set %~2=0
goto :eof
::[DOS_API:isEmptyFolder]test whether folder is empty , result is stored in 2nd parameter
::call e.g : call :isEmptyFolder folderPath bEMpty
:: call :isEmptyFolder d:\temp\ bEMpty //set bEMpty=0
:isEmptyFolder
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
set %~2=1
if not exist "%~1" goto :eof
for /f "usebackq tokens=1" %%i in ( ` dir /b "%~fs1" ^| find /c /v "^^*" ` ) do if not {"%%i"}=={"0"} set %~2=0
goto :eof
::[DOS_API:isSameFile]test whether folder is empty , result is stored in 2nd parameter
::call e.g : call :isSameFile file1 file2 bSame
:: call :isSameFile d:\temp\1.txt d:\dir\2.txt bSame //set bSame=0
:isSameFile
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
call tools_error.bat checkParamCount 3 %*
call tools_error.bat checkFileExist "%~fs1" "%~fs0" mark_MergeTwoFile_1
call tools_error.bat checkFileExist "%~fs2" "%~fs0" mark_MergeTwoFile_2
set %~3=0
call fc "%~fs1" "%~fs2" >nul
if {"%errorlevel%"}=={"0"} set %~3=1
goto :eof
::[DOS_API:isUnicodeFile]test whether file is unicode format
::usage : call :isUnicodeFile srcfilefullpath bRet
::call e.g. : call :isUnicodeFile "%~f0" bRet
:isUnicodeFile
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
:: https://www.robvanderwoude.com/battech_fileencoding.php
call tools_error.bat checkFileExist "%~fs1"
for /f %%i in ( "%~fs1" ) do set "%~2=0" & goto :eof
set %~2=1
goto :eof
::[DOS_API:isAsciiFile]test whether file is ascii format
::usage : call :isAsciiFile srcfilefullpath bRet
::call e.g. : call :isAsciiFile "%~f0" bRet
:isAsciiFile
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [ %~nx0] commandLine: %0 %*
:: https://www.robvanderwoude.com/battech_fileencoding.php
call tools_error.bat checkFileExist "%~fs1"
for /f %%i in ( "%~fs1" ) do set "%~2=1" & goto :eof
set %~2=0
goto :eof
:End
@if defined _Stack @for %%a in ( 1 "%~nx0" "%0" ) do @if {"%%~a"}=={"%_Stack%"} @echo [----- %~nx0] commandLine: %0 %* & @echo.