%20con%20Windows%20CMD%3F%20Parte%202.png)
Esto es en relación conesta pregunta.
Lamentablemente, los scripts de PowerShell están deshabilitados en el sistema en el que estoy trabajando. Ni siquiera puedo usar un simple (Get-Content)
.
Descubrí cómo cambiar cadenas específicas dentro de un archivo PS específico (gracias a las respuestas). Sin embargo, solo puedo hacerlo en un archivo PS a la vez y tuve que editar el archivo por lotes especificando el nombre del archivo PS (está codificado). Todo lo que queda es que el archivo por lotes procese TODOS los archivos PS dentro del mismo directorio (sin subdirectorios).
Aquí está el código:
REM Start of Code
REM Auto-process PS files within a directory
REM Changes how PS files look when displayed
REM This batch file searches for instances of
REM "OldStringx" within the file and replaces it
REM with "NewStringx"
REM Thicken line width from 1 to 5
Set "OldString1=1 setlinewidth"
Set "NewString1=5 setlinewidth"
REM Change Courier font to Helvetica
Set "OldString2=Courier"
Set "NewString2=Helvetica-Bold"
REM To do: This batch file should process all PS files within
REM the same directory where the batch file is located
REM (Batch file and all PS files to be edited should be
REM found on the same path).
REM Specified below is the PS file to edit. Hard-coded for now.
set file="psfile_to_edit.ps"
@echo off
cd /d .
for /F "usebackq delims=" %%F in (`dir *.ps /b`) do set outFile="%%~nF_edited%%~xF"
(
for /f "skip=2 delims=" %%a in ('find /n /v "" %file%') do (
set "ln=%%a"
Setlocal enableDelayedExpansion
set "ln=!ln:*]=!"
if defined ln set "ln=!ln:%OldString1%=%NewString1%!"
if defined ln set "ln=!ln:%OldString2%=%NewString2%!"
echo(!ln!
endlocal
)
)>%outFile%
REM Convert edited PS files to JPG
REM This requires convert.exe to work
REM Currently commented out to debug above parts.
REM convert.exe %outFile% -autocrop %outfile:~0,-4%.jpg
REM End of Code
Básicamente, solo quiero que este código procese todos los archivos PS dentro del mismo directorio. Por favor ayuda. ¡Y gracias de antemano!
Respuesta1
no probado
@ECHO OFF &SETLOCAL
cd /d .
for %%x in (*.ps) do call:process "%%~x"
goto:eof
:process
set "outFile=%~n1_edited%~x1"
(for /f "skip=2 delims=" %%a in ('find /n /v "" "%~1"') do (
set "ln=%%a"
Setlocal enableDelayedExpansion
set "ln=!ln:*]=!"
if defined ln (
set "ln=!ln:%OldString1%=%NewString1%!"
set "ln=!ln:%OldString2%=%NewString2%!"
)
echo(!ln!
endlocal
))>"%outFile%"
exit /b
Respuesta2
Finalmente, después de más de 2 semanas, ¡este código finalmente funciona! Créditos a Endoro.
REM Start of Code
REM Auto-process PS files within a directory
REM Changes how PS files look when displayed
REM This batch file searches for instances of
REM "OldStringx" within the file and replaces it
REM with "NewStringx"
REM Thicken line width from 1 to 5
Set "OldString1=1 setlinewidth"
Set "NewString1=5 setlinewidth"
REM Change Courier font to Helvetica
Set "OldString2=Courier"
Set "NewString2=Helvetica-Bold"
@ECHO OFF &SETLOCAL
cd /d .
for %%x in (*.ps) do call:process "%%~x"
goto:eof
:process
set "outFile=%~n1_edited%~x1"
(for /f "skip=2 delims=" %%a in ('find /n /v "" "%~1"') do (
set "ln=%%a"
Setlocal enableDelayedExpansion
set "ln=!ln:*]=!"
if defined ln (
set "ln=!ln:%OldString1%=%NewString1%!"
set "ln=!ln:%OldString2%=%NewString2%!"
)
echo(!ln!
endlocal
))>"%outFile%"
exit /b
REM Convert edited PS files to JPG
REM This requires convert.exe to work
REM Currently commented out to debug above parts.
REM convert.exe %outFile% -autocrop %outfile:~0,-4%.jpg
REM End of Code
Pasemos a la última parte (conversión a imagen). Muchas gracias de nuevo a @Endoro (¡mwahugs!).
Respuesta3
Sólo para que conste, código de una línea en Linux
find /home/usuario/micarpeta/ -name *.txt -exec sed -i "s/OldStringx/NewStringx/g" {} \