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-ID: 116539

Url: https://administrator.de/forum/frage-zum-loeschen-116539.html

Ausgedruckt am: 06.04.2025 um 09:04 Uhr

bastla
bastla 21.05.2009 um 16:56:12 Uhr
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@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
Motorcross
Motorcross 21.05.2009 um 18:05:51 Uhr
Goto Top
Hallo bastla,
es funktioniert einwandfrei!
Gruß Motorcross