评估用户定义变量的第一个字符是大写

时间:2013-05-01 00:10:08

标签: command-line for-loop cmd uppercase

我有一个模板文档,我想将其转换为具有用户定义名称的另一个文件。以下是我拼凑的代码。

rem @echo off
setlocal enableDelayedExpansion

cls

:Check_Filename
set "_Filename="
set /p _Filename=Enter filename to be created:

if not defined _Filename echo You must enter a value. Try again.&goto Check_Filename

set "test=%_Filename:~0,1%"

for %%C in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if defined test set "test=!test:%%C=!"

if defined test echo Invalid input. Try again.&goto Check_Filename

if not defined test echo %_Filename%
Set "errorlevel="
echo %_Filename% | findstr /i /R ".java" > nul

if %errorlevel% == 0 (
echo Java extention located
type f:\java\Template.txt > f:\java\%_Filename%
echo %errorlevel% 

) else (
echo Java extention not located
echo %errorlevel%
type f:\java\Template.txt > f:\java\%_Filename%.java
)
)

它有效,但因为该文件被用于创建Java脚本的主干,所以我希望FOR语句来评估它当前不会执行的第一个字符的情况。我也尝试在FOR语句中使用这些字符的HEX表示,但没有成功。

有人可以帮助我吗?

谢谢。

1 个答案:

答案 0 :(得分:2)

试试这个:

@echo off & setlocal
:Check_Filename
set "_Filename="
set /p "_Filename=Enter filename to be created: "

if not defined _Filename echo You must enter a value. Try again.&goto:Check_Filename

echo(%_Filename:~0,1% | findstr /r "[ABCDEFGHIJKLMNOPQRSTUVWXYZ]" || (echo Invalid input. Try again.&goto:Check_Filename)