39263
Goto Top

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?

Content-Key: 46161

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

Printed on: April 18, 2024 at 20:04 o'clock

Member: AxelHahn
AxelHahn Dec 06, 2006 at 14:08:00 (UTC)
Goto Top
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


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

set sDir=%~dpvar%
echo md "C:\Test\%sDir%"


zum "Scharfmachen" echo entfernen.


Viele Grüsse
-= Axel =-
Member: Biber
Biber Dec 06, 2006 at 14:50:03 (UTC)
Goto Top
Zum Sichtbar- bzw. Deutlichmachen der von AxelHahn geposteten Lösung gib einfach mal am CMD-Prompt ein:
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
- FOR-Zählvariablen
- den Übergabeparametern %1, %2 ...%9 beim Aufruf eines Batches oder eines CALL-Blocks.

Die AxelHahn-Zeile...
 set sDir=%~dpvar%
geht also nicht, sondern muss heißen
 set sDir=%~dp1
[...also "gib mir Laufwerk und Pfad vom Übergabeparameter %1"]
Wobei eben eigentlich kein CALL-Block nötig ist.
[/Edit]
Mitglied: 39263
39263 Dec 06, 2006 at 15:22:46 (UTC)
Goto Top
so, hab's endlich geschafft. hatte noch ein paar probleme diesen teil in das eigentliche skript einzubauen...
aber nun funktioniert es einwandfrei und tut auch endlich das, was es soll ;)
vielen dank für die schnelle antwort.