Batch file 将通配符批量链接到脚本

Batch file 将通配符批量链接到脚本,batch-file,Batch File,你好,有人让我再问一个问题 我想看看如何将这一行添加到我当前的脚本中 FOR /f "delims=" %%q IN ('dir /b /s /a-d "%source%\(1)*.txt"') DO ( 或者,如果我能得到帮助,将“文件”和“文件名”更新到这个(1)*.txt,那也太好了 @ECHO OFF SETLOCAL ECHO STARTING 1 For %%G In ("%~dp0..\New Folder 1")

你好,有人让我再问一个问题

我想看看如何将这一行添加到我当前的脚本中

FOR /f "delims=" %%q IN ('dir /b /s /a-d "%source%\(1)*.txt"') DO (
或者,如果我能得到帮助,将“文件”和“文件名”更新到这个
(1)*.txt
,那也太好了

@ECHO OFF
SETLOCAL 

ECHO STARTING 1

For %%G In ("%~dp0..\New Folder 1") Do Set "source=%%~fG"
For %%G In ("%~dp0..\New Folder 2") Do Set "target=%%~fG"
For %%G In ("%~dp0..\New Folder 3") Do Set "destdir=%%~fG"

set "FILE=(1) Homes in Texas.txt"
set "FILENAME=(1) Homes in Texas.txt"

for /f "tokens=1 delims=[]" %%a in ('find /n "appi"^<"%source%\%file%"') do set /a start=%%a
for /f "tokens=1 delims=[]" %%a in ('find /n "opcn"^<"%source%\%file%"') do set /a end=%%a
(
for /f "tokens=1* delims=[]" %%a in ('find /n /v ""^<"%source%\%file%"') do (
 IF %%a geq %start% IF %%a leq %end% ECHO(%%b
 )
)>"%target%\(A)_sets.txt"

for /f "tokens=1 delims=[]" %%a in ('find /n "paid"^<"%source%\%file%" ') do set /a start=%%a
for /f "tokens=1 delims=[]" %%a in ('find /n "whbn"^<"%source%\%file%" ') do set /a end=%%a
(
for /f "tokens=1* delims=[]" %%a in ('find /n /v ""^<"%source%\%file%" ') do (
 IF %%a geq %start% IF %%a leq %end% ECHO(%%b
 )
)>"%target%\(B)_sets.txt"

If Exist "%target%\*.txt" If Exist "%destdir%\" (
    Copy /Y /B "%target%\(A)_Sets.txt" + "%target%\(B)_Sets.txt" "%destdir%\(1).txt"
)

ren "%destdir%\(1).txt" "%filename%"

If Exist "%source%\(2) *.txt" (
     call "%~dp0(2) Extraction tool.bat"
)

GOTO :EOF
他们都在文件名中有(?)以便查找(1)*.txt,但不知道这是否是使用(1)*.txt的
ren“%destdir%\(1.txt”“%filename%”的问题

如果有办法修复我的文件和文件名以处理(1)*.txt并保留原始文件名作为最终结果,我们将不胜感激

任何帮助都将是巨大的

这是否正确,当我以这种方式或任何其他方式设置时,我会得到空白文件[corrected code below.Stephan]

REM not here... set "FILE=%~1"
set "FILENAME=(1) Homes in Texas.txt"

FOR /f "delims=" %%q IN ('dir /b /s /a-d "%source%\(1)*.txt"') DO call :label "%%q"
goto :eof
:Label
REM here "%~1" gets the value "%%q" from the CALL command, a FQDN (filename including drive and path because of 'dir /s /b')
for /f "tokens=1 delims=[]" %%a in ('find /n "appi"^<"%~1"') do set /a start=%%a
现在差不多准备好了,我们用那行代码修复了
文件

仍在处理
文件名

If Exist "%target%\*.txt" If Exist "%destdir%\" (
        Copy /Y /B "%target%\(A)_Sets.txt" + "%target%\(B)_Sets.txt" "%destdir%\(1).txt"
    )
    
    ren "%destdir%\(1).txt" "%filename%"
If Exist "%target%\*.txt" If Exist "%destdir%\" (
            Copy /Y /B "%target%\(A)_Sets.txt" + "%target%\(B)_Sets.txt" "%destdir%\(1).txt"
        )
        
        ren "%destdir%\(1).txt" "(*)A.txt"
我知道通配符确实适用于
ren
我测试了它以确认
*

If Exist "%target%\*.txt" If Exist "%destdir%\" (
        Copy /Y /B "%target%\(A)_Sets.txt" + "%target%\(B)_Sets.txt" "%destdir%\(1).txt"
    )
    
    ren "%destdir%\(1).txt" "%filename%"
If Exist "%target%\*.txt" If Exist "%destdir%\" (
            Copy /Y /B "%target%\(A)_Sets.txt" + "%target%\(B)_Sets.txt" "%destdir%\(1).txt"
        )
        
        ren "%destdir%\(1).txt" "(*)A.txt"
%destdir%
中,它重命名为
(1)A.txt
,这样通配符就可以看到
(1)


我如何设置它以获取
源文件夹中文件名上的匹配
(1)
,并使用该文件名重命名“%destdir%文件夹中的
(1).txt

@aschipfl-你好,我有我的问题ready@Compo-你能帮我吗-试着看看是否有可能更正
set“FILE=(1)德克萨斯州的家.txt“
“文件=(1)*.txt”
将“文件名=(1)德克萨斯州的家.txt”
设置为我的当前脚本,当我尝试为/f“delims=”%%q in('dir/b/s/a-d”%source%\(1)*.txt“)调用:label“%%q”
。下面
:label
应该是处理一个文件的现有代码(不要忘记更改为
设置“file=%~1”
)@Stephan-谢谢你,我不知道我必须将
文件设置为%%1
,我们之所以设置它是因为我有
令牌=1
correct@Stephan-我不能让它工作,我的文件是空白打印的,我更新了我的问题以显示我是如何设置的