%20com%20o%20Windows%20CMD%3F%20Parte%202.png)
Isto é em relaçãoessa questão.
Infelizmente, os scripts do PowerShell estão desabilitados no sistema em que estou trabalhando. Não consigo nem usar um arquivo (Get-Content)
.
Eu descobri como alterar strings específicas em um arquivo PS específico (graças às respostas). No entanto, só posso fazer isso em um arquivo PS por vez e tive que editar o próprio arquivo em lote especificando o nome do arquivo PS (está codificado). Tudo o que resta é que o arquivo em lote processe TODOS os arquivos PS no mesmo diretório (sem subdiretórios).
Aqui está o 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
Fundamentalmente, quero apenas fazer com que esse código processe todos os arquivos PS no mesmo diretório. Por favor ajude. E obrigado antecipadamente!
Responder1
não testado
@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
Responder2
Finalmente, depois de mais de 2 semanas, este código finalmente funciona! Créditos ao 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
Vamos para a última parte (conversão para foto). Muito obrigado novamente a @Endoro (mwahugs!).
Responder3
Só para constar, código de uma linha no Linux
find /home/usuario/micarpeta/ -name *.txt -exec sed -i "s/OldStringx/NewStringx/g" {} \