motorcross
Goto Top

Frage zum löschen

Hallo Administratoren,

eine Batch Datei erstellt 9 .txt Dateien z.b :
test1.txt
test2.txt
usw. bis 9
wenn jetzt die zehnte Datei erstellt wird soll die erste gelöscht werden und um eine Zahl zurück benannt werden.
also txt. Datei 2 soll dann zu .txt datei 1 umbenannt werden.
Gruß Motorcross

Content-Key: 116539

Url: https://administrator.de/contentid/116539

Printed on: April 25, 2024 at 06:04 o'clock

Member: bastla
bastla May 21, 2009 at 14:56:12 (UTC)
Goto Top
Hallo Motorcross!

Unter der Annahme, dass die 10. Datei einfach nur "test.txt" (bzw, etwas genauer: "%Basis%\%Dateiname%.%Dateityp%") heißt, etwa so:
@echo off & setlocal
set "Basis=D:\Test"  
set "Dateiname=test"  
set "Dateityp=txt"  
set /a Max=9

set /a NrNeu=Max+1
move "%Basis%\%Dateiname%.%Dateityp%" %Basis%\%Dateiname%%NrNeu%.%Dateityp%"  
for /L %%i in (1,1,%Max%) do call :ProcessFile %%i

goto :eof

:ProcessFile
set /a Nr=%1+1
set "Datei=%Basis%\%Dateiname%%Nr%.%Dateityp%"  
if exist "%Datei%" move "%Datei%" "%Basis%\%Dateiname%%1.%Dateityp%"  
goto :eof
Sollte die neue Datei aber ohnehin schon "test10.txt" heißen, können die Zeilen 7 und 8 entfallen.

Grüße
bastla
Member: Motorcross
Motorcross May 21, 2009 at 16:05:51 (UTC)
Goto Top
Hallo bastla,
es funktioniert einwandfrei!
Gruß Motorcross