%20suchen%20und%20ersetzen%3F%20Teil%202.png)
Dies ist im Zusammenhang mitdiese Frage.
Leider sind PowerShell-Skripte auf dem System, an dem ich arbeite, deaktiviert. Ich kann nicht einmal ein einfaches verwenden (Get-Content)
.
Ich habe herausgefunden, wie man bestimmte Zeichenfolgen in einer bestimmten PS-Datei ändert (dank der Antworten). Allerdings kann ich das nur für eine PS-Datei gleichzeitig tun und musste die Batchdatei selbst bearbeiten, indem ich den Namen der PS-Datei angegeben habe (er ist fest codiert). Jetzt muss die Batchdatei nur noch ALLE PS-Dateien im selben Verzeichnis verarbeiten (keine Unterverzeichnisse).
Hier ist der Code:
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
Im Grunde möchte ich nur, dass dieser Code alle PS-Dateien im selben Verzeichnis verarbeitet. Bitte helfen Sie. Und vielen Dank im Voraus!
Antwort1
ungetestet
@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
Antwort2
Endlich, nach mehr als 2 Wochen, funktioniert dieser Code endlich! Dank an 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
Weiter zum letzten Teil (Konvertierung in Bild). Nochmals vielen Dank an @Endoro (mwahugs!).
Antwort3
Nur zur Info, einzeiliger Code in Linux
find /home/usuario/micarpeta/ -name *.txt -exec sed -i "s/OldStringx/NewStringx/g" {} \