一个bat脚本涉及获取传参、访问ftp下载文件、循环、字符串处理等

@echo off
set WORKSPACE=%1
SET FTPIP=%2
set FTPPATH=%3
set PKGLIST="%4"
set EBUY=%5
set SPASS=%6
set KPASS=%7
SET FILENAME=%8
setlocal enabledelayedexpansion


if %WORKSPACE%! == ! ( echo "WORKSPACE not set correctly" & goto END )
if %FTPIP%! == ! ( echo "FTPIP not set correctly" & goto END )
if %FTPPATH%! == ! ( echo "FTPPATH not set correctly" & goto END )
if %PKGLIST%! == ! ( echo "PKGLIST not set correctly" & goto END )
if %EBUY%! == ! ( echo "EBUY not set correctly" & goto END )
if %SPASS%! == ! ( echo "SPASS not set correctly" & goto END )
if %KPASS%! == ! ( echo "KPASS not set correctly" & goto END )
if %FILENAME%! == ! ( echo "FILENAME not set correctly" & goto END )

if not exist %WORKSPACE% ( echo "%WORKSPACE% not exist" & goto END )

:delright
if "%WORKSPACE:~-1%"=="\" set WORKSPACE=%WORKSPACE:~0,-1%&&goto delright


echo %WORKSPACE%
echo %FTPPATH%
echo %PKGLIST%
echo %FTPIP%
echo %FILENAME%

set ftpUser=test
set ftpPass=test
::10.27.205.4
set LocalFolder=%WORKSPACE%
set FtpFile=getftpfile.txt
echo open %FTPIP% > %FtpFile%
echo user %ftpUser% %ftpPass% >> %FtpFile%
REM echo cd %ftpFolder% >> %FtpFile%
echo lcd %LocalFolder% >>%FtpFile%  
echo prompt off >>%FtpFile%
echo bin >> %FtpFile%
echo get %FTPPATH% >> %FtpFile%
echo bye >> %FtpFile%
ftp -n -s:%FtpFile%
del %FtpFile%

cd /d c:\
@echo off
:loop
for /f "delims=,, tokens=1,*" %%i in (%PKGLIST%) do (
    echo %%i %%j
    set PKGLIST="%%j"
    set LOCALPATH=%LocalFolder%\%%i
	set APKPATH=!LOCALPATH:/=\!
    echo !APKPATH!
    for /f  %%j in ('dir /b/s/a !APKPATH! ^| find /v "sign"') do (
        set sfile=%%j
        set sfile=!sfile:.apk=sign.apk!
        jarsigner -storepass %SPASS% -keypass %KPASS%  -verbose -keystore %LocalFolder%\%FILENAME% -signedjar !sfile! %%j  %EBUY%
		::删除未签名的文件
		del /f /s /q %%j
    )
    goto loop
    )


你可能感兴趣的:(shell脚本)