2

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

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 语句中使用这些字符的十六进制表示,但没有成功。

有人可以帮我吗?

谢谢你。

4

1 回答 1

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)
于 2013-05-01T02:10:49.143 回答