How can I remove ":" from a string in batch file?

时间:2018-01-23 19:12:53

标签: batch-file

How can I get rid of ":" from my string in a batch file?

for /f "tokens=1,2,3,6,7 skip=6 delims= " %%f in (%FILE_LIST%) do (
java -jar D:\HDLdi2.3.9\lib\oracle.ucm.fa_client_11.1.1.jar DownloadTool --dID=%%f --url=%UCM_Link% --username=%_UserName% --password=%_Password% "--outputfile=E:\FusionData\Outbound\%PROPERTY%\Temp\%FILE_NAME%_%%i_%%j.txt"
)

I got the error message because I have %%i as 2018-01-23 and %%j as 13:12:11Z and %%j have ":" in my output file extension.

Sorry for misleading for the first question. Thanks a lot!

2 个答案:

答案 0 :(得分:1)

You could probably do this:

SetLocal EnableDelayedExpansion
For /F "Skip=6 Tokens=1,2,3,6,7 Delims= " %%f In (%FILE_LIST%) Do (
    Set "FFNAME=%%i_%%j"
    Set "FFNAME=!FFNAME:-=!"
    Set "FFNAME=!FFNAME::=!"
    Set "FFNAME=!FFNAME:~,15!"
    java -jar D:\HDLdi2.3.9\lib\oracle.ucm.fa_client_11.1.1.jar DownloadTool --dID=%%f --url=%UCM_Link% --username=%_UserName% --password=%_Password% "--outputfile=E:\FusionData\Outbound\%PROPERTY%\Temp\%FILE_NAME%_!FFNAME!.txt"
)

答案 1 :(得分:0)

String manipulation in batch isn't particularly complicated, if a bit unintuitive. The way this can be handled is %<variable>:<string to remove>=%

For your case,

set FFNAME=%FDATE:-=%%FTIME::=%
set FFNAME=%FFNAME:Z=%

yeilds the string

20180123131211

See this reference for more details. https://www.dostips.com/DtTipsStringManipulation.php