선택한 캐릭터를 얻는 방법
for %%A in (controls\vbalSGrid6.ocx) do (
SET TEXT=%A%
SET SUBSTRING=%TEXT:~9%
echo %SUBSTRING%
)
이것은 에코가 꺼져 있지만 나는 필요합니다 vbalsgrid6.ocx
.
직접적인 방법
set "text=controls\vbalscrid6.ocx"
set "substring=%text:~9%"
대한 필요가 없습니다 for
명령, 당신은 파일 세트 이상 반복하는이다하거나 파일 이름을 얻기 위해 작업을 하위 문자열 사용하지 않는 한
파일의 이름과 확장자를 얻는 쉬운 방법
for %%a in (controls\vbalsgrid6.ocx) do set "fileName=%%~nxa"
%%a
파일에 대한 참조를 보유하고 참조 된 파일 %%~nxa
의 파일 이름 및 확장자입니다.
코드 의 직접 번역 / 수정 된 버전 (이 경우 파일 목록을 반복하지만 필요하지 않음)
@echo off
setlocal enableextensions enabledelayedexpansion
for %%a in (controls\*.ocx) do (
set "text=%%a"
set "substring=!text:~9!"
echo !substring!
)
배치 파서가 코드 줄 / 블록 (괄호 안의 코드)에 도달하면 변수를 읽을 위치를 검색하여 전체 줄 / 블록을 확인합니다. 이 모든 읽기는 라인 / 블록이 실행 되기 전에 구문 분석시 변수에 저장된 값으로 대체됩니다 . 즉, 변수가 블록 내에서 값을 변경하면이 변경된 값은 변수에 대한 읽기 작업이 이전에 그 안에 저장된 초기 값으로 대체되었으므로 동일한 블록 내에서 액세스 할 수 없습니다.
이 경우를 처리하기 위해 지연된 확장이 사용됩니다. 지연 확장을 사용할 수있는 경우에서, 변수를 판독하는 구문 (필요한) 변경할 수 %var%
에 !var!
명령이 실행될 때까지 판독 동작이 지연되어야하는 파서 나타낸다.
포함 된 코드는 !
파일 이름에 없는 동안 작동 합니다. 지연된 확장이 활성화되면 파서가 any를 해석하려고 시도하여 !
경우에 따라 예상치 못한 결과를 제공합니다. 처리 할 수 있지만 때로는 약간 까다로울 수 있습니다.
@echo off
setlocal enableextensions disabledelayedexpansion
for %%a in (controls\*.ocx) do (
rem Retrieve the initial text. No problem as delayed expansion is disabled
set "text=%%a"
rem Enable delayed expansion to read the value in %text%. And ensure
rem it is disabled at the moment of the assignment to the substring var
setlocal enabledelayedexpansion
set "substring="
for /f "delims=" %%b in ("!text:~9!") do (endlocal & set "substring=%%b")
rem We need delayed expansion enabled to read the changed value
rem If substring is empty, the previous endlocal was not executed and
rem there is no need for a new setlocal
if defined substring setlocal enabledelayedexpansion
echo(substring value=!substring!
endlocal
)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다