tomilai
Goto Top

Einzelne TXT Files mittels Batch kopieren und in oder nach separate Ordner speichern oder verschieben

Hallo,

ich habe einige Ordner mit Textdatei (um die 100).
Ich möchte all diesen Dateien in separaten Ordnern speichern.

Original Ordner:

Ordner Name: PC
Berta_PC01.txt
Berta_PC02.txt
Berta_PC03.txt
Berta_PC04.txt
Berta_PC05.txt
---------------------------
Thomas_PC01.txt
Thomas_PC02.txt
Thomas_PC03.txt
Thomas_PC04.txt
Thomas_PC05.txt
-----------------------------
Richard_PC01.txt
Richard_PC02.txt
Richard_PC03.txt
Richard_PC04.txt
Richard_PC05.txt

Ordner Name: Tablet
Berta_Tablet01.txt
Berta_Tablet02.txt
Berta_Tablet03.txt
Berta_Tablet04.txt
Berta_Tablet05.txt
---------------------------
Thomas_Tablet01.txt
Thomas_Tablet02.txt
Thomas_Tablet03.txt
Thomas_Tablet04.txt
Thomas_Tablet05.txt
-----------------------------
Richard_Tablet01.txt
Richard_Tablet02.txt
Richard_Tablet03.txt
Richard_Tablet04.txt
Richard_Tablet05.txt

Ordner Name: Handy
Berta_Handy01.txt
Berta_Handy02.txt
Berta_Handy03.txt
Berta_Handy04.txt
Berta_Handy05.txt
---------------------------
Thomas_Handy01.txt
Thomas_Handy02.txt
Thomas_Handy03.txt
Thomas_Handy04.txt
Thomas_Handy05.txt
-----------------------------
Richard_Handy01.txt
Richard_Handy02.txt
Richard_Handy03.txt
Richard_Handy04.txt
Richard_Handy05.txt
ZielOrdner:
Ordner Name: PC01
Berta_PC01.txt
Thomas_PC01.txt
Richard_PC01.txt
-------------
Ordner Name : Tablet01
Berta_Tablet01.txt
Thomas_Tablet01.txt
Richard_Tablet01.txt

...usw für alle weiter Ordner.
Manuel ist es machbar, nur mühsam. Ich dachte an einer for Schleife, nur ich weiß nicht welche Bedienung soll es sein, und wie die Ausgabe aussehen soll?

Ich hoffe das Problem ist klar.
Vielen Dank und Schöne Grüße
Thomas

Content-Key: 314732

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

Printed on: May 8, 2024 at 14:05 o'clock

Member: Kraemer
Kraemer Sep 08, 2016 at 10:25:43 (UTC)
Goto Top
Moin,

siehe z.B. da

Gruß Krämer
Member: Tomilai
Tomilai Sep 08, 2016 at 11:56:13 (UTC)
Goto Top
Hallo Kraemer,
vielen Dank für den Hinweis. Ich habe dies probiert, aber scheint nicht ganz zu funktionieren.

@echo off 

REM für jedes File im akt. Ordner (for /r)
for /r "delims=" %%i in ('dir /b/a-d "*"') do (   

REM Nehme die Endung des Files(z.b Berta_PC01-->PC01)
	for /f "tokens=3 delims=-." %%a in ("%%i") do (   

REM Erstelle einen neuen Ordner Mit dem gleichen Namen wie die Endung jedes Files
 		md "C:\Users\Thomas\Desktop\Probe\%%a"  
REM Zur Kontrolle zeige jeden Namen 
                echo %%a
REM Verschiebe jedes Files mit der Endung(01,02...) zum Ordner mit dem entsprechenden Namen
 		move "*%%a*.*" "%C:\Users\Thomas\Desktop\Probe\%%a%"   

	) 

 )
pause

Eine Idee woran es liegen könnte?
Vielen Dank und schöne Grüße
Thomas
Mitglied: 129813
129813 Sep 08, 2016 updated at 12:04:51 (UTC)
Goto Top
powershell -Executionpoliy ByPass -Command "gci 'C:\pc\*.txt' | group {$_.Basename.Split('_')[1]} | %%{$target = \"C:\pc\$($_.Name)\"; if(!(Test-Path $target)){md $target}; $_.Group | move-item -Destination $target -Force}"  
Please read:
Musterlösungen: Dateien verschieben abhängig vom Teil des Dateinamens
Question comes two times a day ... face-confused

Regards
Member: Tomilai
Tomilai Sep 10, 2016 at 12:50:24 (UTC)
Goto Top
Hi highload,
Thanks a lot. I've tried your code, but seems not to work.

I just tried this:
@echo off & setlocal 
mkdir PC01, PC02, PC03

move *_PC01.txt PC01
move *_PC02.txt PC02
move *_PC03.txt PC03

and did the work as expected.

My question was about
1) Creating those folders automaticly
2) automaticly moving the right files to the adequate location

It will be great to use a batch date for this.

Many thank and best regards
Thomas
Mitglied: 129813
129813 Sep 10, 2016 at 17:54:59 (UTC)
Goto Top
Zitat von @Tomilai:

Hi highload,
Thanks a lot. I've tried your code, but seems not to work.
Works, tested it.
It will be great to use a batch date for this.
See the linked thread above for batch code. Why repeating everything 2 times a day ???