
Estoy tratando de escribir un archivo por lotes simple, pequeño y flexible que sea fácil de modificar para diferentes fabricantes que revisará una lista de archivos Gerber creados en Proteus y les cambiará el nombre de manera adecuada.
Este conjunto es para Seeed Studio.
El problema que tengo es que solo se está corrigiendo la extensión, necesito reemplazar toda la cadena.
es decir, "Circuito - CADCAM Bottom Copper.TXT" se convierte en "Circuito.GBL", etc.
Actualmente "Circuito - CADCAM Bottom Copper.TXT" se convierte en "Circuito - CADCAM Bottom Copper.GBL"
Gracias por la ayuda,
Haydan
@echo off
Setlocal enabledelayedexpansion
REM Check all files are present and rename
set MISSING=0
call :CheckFile " - CADCAM Bottom Copper.TXT", ".GBL"
call :CheckFile " - CADCAM Bottom Copper", "-"
call :CheckFile " - CADCAM Bottom Silk Screen.TXT", ".GBO"
call :CheckFile " - CADCAM Bottom Solder Resist.TXT", ".GBS"
call :CheckFile " - CADCAM Drill.TXT", ".TXT"
call :CheckFile " - CADCAM Mechanical 1.TXT", ".GKO"
call :CheckFile " - CADCAM Top Copper.TXT", ".GTL"
call :CheckFile " - CADCAM Top Silk Screen.TXT", ".GTO"
call :CheckFile " - CADCAM Top Solder Resist.TXT", ".GTS"
REM if exist "Internal Plane 1.ger" call :CheckFile "Internal Plane 2.ger", ""
if %MISSING% EQU 0 (
echo Success - all files found!
pause
goto :eof
) else (
echo %MISSING% file^(s^) missing.
pause
goto :eof
)
REM Rename as found or flag erro
:CheckFile
if not exist *%1 (
echo ERROR: Missing %1!
set /a MISSING=%MISSING% + 1
) else (
echo %1
echo %2
ren *%1 *%2
)
Respuesta1
El siguiente :CheckFile
procedimiento debería hacer el trabajo:
:CheckFile
set "_string=%~1"
if not exist *%1 (
echo ERROR: Missing %1!
set /a MISSING+=1
) else (
for /F "delims=" %%G in ('dir /B "*%~1"') do (
set "_fileA=%%~G"
set "_fileB=!_fileA:%_string%=!"
rem next `rename` command is merely ECHOed for debugging purposes
ECHO ren "%%~G" "!_fileB!%~2"
)
)
goto :eof
Nota: rename
el comando simplemente se hace ECHO con fines de depuración en el fragmento de código anterior; ¡elimine el encabezado ECHO
(use ren "%%~G" "!_fileB!%~2"
) tan pronto como se haya depurado!
Producción:
==> D:\bat\SU\1119379.bat
ren "Circ #2 - CADCAM Bottom Copper.TXT" "Circ #2.GBL"
ren "Circuit - CADCAM Bottom Copper.TXT" "Circuit.GBL"
ren "Circuit - CADCAM Bottom Copper" "Circuit-"
ERROR: Missing " - CADCAM Bottom Silk Screen.TXT"
ERROR: Missing " - CADCAM Bottom Solder Resist.TXT"
ERROR: Missing " - CADCAM Drill.TXT"
ERROR: Missing " - CADCAM Mechanical 1.TXT"
ERROR: Missing " - CADCAM Top Copper.TXT"
ERROR: Missing " - CADCAM Top Silk Screen.TXT"
ERROR: Missing " - CADCAM Top Solder Resist.TXT"
7 file(s) missing.
Press any key to continue . . .
Recursos(lectura obligatoria, incompleta):
- (referencia de comando)Un índice AZ de la línea de comando CMD de Windows
- (particularidades adicionales)Sintaxis de la línea de comandos de Windows CMD Shell
- (
%~G
,%~1
etc. página especial)Argumentos de la línea de comando (parámetros) - (
set "_fileB=!_fileA:%_string%=!"
etc.)Editar/reemplazar variables