
39263
06.12.2006, aktualisiert um 16:22:46 Uhr
batchdatei - ordner wie eine datei benennen
hallo,
ich brauche eine batchdatei die mir mehrere ordner erstellt, welche wie gespeicherte pdf-dokumente heißen. das problem ist, dass das skript eigentlich nicht weiß wie die dokumente heißen. nun wollt ich über den befehl
dir C:\test /B > C:\test\verz.txt
die namen der dokumente eben in eine txt-datei speichern und dann über eine schleife
For /f "tokens=*" %%i IN C:\test\verz.txt) DO call:benennen %%i
:benennen
set var=%1
md C:\Test\%var%
die namen auslesen und die ordner dementsprechend erstellen und benennen.
dummerweise heißen meine ordner dann xyz.pdf
ich möchte aber, dass sie nur xyz heißen...
hat jmd nen brauchbaren vorschlag?
ich brauche eine batchdatei die mir mehrere ordner erstellt, welche wie gespeicherte pdf-dokumente heißen. das problem ist, dass das skript eigentlich nicht weiß wie die dokumente heißen. nun wollt ich über den befehl
dir C:\test /B > C:\test\verz.txt
die namen der dokumente eben in eine txt-datei speichern und dann über eine schleife
For /f "tokens=*" %%i IN C:\test\verz.txt) DO call:benennen %%i
:benennen
set var=%1
md C:\Test\%var%
die namen auslesen und die ordner dementsprechend erstellen und benennen.
dummerweise heißen meine ordner dann xyz.pdf
ich möchte aber, dass sie nur xyz heißen...
hat jmd nen brauchbaren vorschlag?
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 46161
Url: https://administrator.de/forum/batchdatei-ordner-wie-eine-datei-benennen-46161.html
Ausgedruckt am: 21.05.2025 um 04:05 Uhr
3 Kommentare
Neuester Kommentar
Hi
rufe mal "for /?" auf - da steht drin, dass man von einer Variable Pfad, Extension, ... extrahieren kann. Ergänzend schaue noch in "set /?"
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:
%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
The modifiers can be combined to get compound results:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
set sDir=%~dpvar%
echo md "C:\Test\%sDir%"
zum "Scharfmachen" echo entfernen.
Viele Grüsse
-= Axel =-
rufe mal "for /?" auf - da steht drin, dass man von einer Variable Pfad, Extension, ... extrahieren kann. Ergänzend schaue noch in "set /?"
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:
%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string
The modifiers can be combined to get compound results:
%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
hallo,
ich brauche eine batchdatei die mir mehrere
ordner erstellt, welche wie gespeicherte
pdf-dokumente heißen. das problem ist,
dass das skript eigentlich nicht weiß
wie die dokumente heißen. nun wollt ich
über den befehl
dir C:\test /B > C:\test\verz.txt
die namen der dokumente eben in eine
txt-datei speichern und dann über eine
schleife
For /f "tokens=*" %%i IN
C:\test\verz.txt) DO call:benennen %%i
:benennen
set var=%1
ich brauche eine batchdatei die mir mehrere
ordner erstellt, welche wie gespeicherte
pdf-dokumente heißen. das problem ist,
dass das skript eigentlich nicht weiß
wie die dokumente heißen. nun wollt ich
über den befehl
dir C:\test /B > C:\test\verz.txt
die namen der dokumente eben in eine
txt-datei speichern und dann über eine
schleife
For /f "tokens=*" %%i IN
C:\test\verz.txt) DO call:benennen %%i
:benennen
set var=%1
set sDir=%~dpvar%
echo md "C:\Test\%sDir%"
zum "Scharfmachen" echo entfernen.
Viele Grüsse
-= Axel =-
Zum Sichtbar- bzw. Deutlichmachen der von AxelHahn geposteten Lösung gib einfach mal am CMD-Prompt ein:
Sollte das Ergebnis (=reine Anzeige, der macht nix kaputt!) mit dem übereinstimmen, was Du wolltest,
dann einfach diese Zeile als Batch-Oneliner abspeichern.
HTH Biber
[Edit] Anmerkung:
Wie in der M$-Hilfe auch in vielen Sprachen geschrieben steht:
- FOR-Zählvariablen
- den Übergabeparametern %1, %2 ...%9 beim Aufruf eines Batches oder eines CALL-Blocks.
Die AxelHahn-Zeile...
geht also nicht, sondern muss heißen
[...also "gib mir Laufwerk und Pfad vom Übergabeparameter %1"]
Wobei eben eigentlich kein CALL-Block nötig ist.
[/Edit]
For /f "delims=" %i IN ('dir /a-d /b c:\test\*.*') DO @echo md "%~dpni" ^& move "%~dpnxi" "%~dpni\"
Sollte das Ergebnis (=reine Anzeige, der macht nix kaputt!) mit dem übereinstimmen, was Du wolltest,
dann einfach diese Zeile als Batch-Oneliner abspeichern.
@For /f "delims=" %%i IN ('dir /A:-d /b c:\test\*.*') DO @md "%%~dpni" & move "%%~dpnxi" "%%~dpni\"
HTH Biber
[Edit] Anmerkung:
Wie in der M$-Hilfe auch in vielen Sprachen geschrieben steht:
....substitution of FOR variable references has been enhanced
-bzw. -
Zusätzlich wurde die Ersetzung von Verweisen auf FOR-Variablen erweitert
> dieses "%~dp"-usw.-Geraffel fünktioniert nur bei-bzw. -
Zusätzlich wurde die Ersetzung von Verweisen auf FOR-Variablen erweitert
- FOR-Zählvariablen
- den Übergabeparametern %1, %2 ...%9 beim Aufruf eines Batches oder eines CALL-Blocks.
Die AxelHahn-Zeile...
set sDir=%~dpvar%
set sDir=%~dp1
Wobei eben eigentlich kein CALL-Block nötig ist.
[/Edit]