robx
Goto Top

Rekursiv Dateien mit identischen Namen (aber unterschiedlicher Endung) verschieben

Hallo,

ich will rekursiv Dateien mit identischen Namen, aber Endung
ENTWEDER .odt/.doc
ODER .ods/.xls
finden, prüfen ob der Name tatsächlich identisch ist und die
gefundenen .doc und .xls Dateien in ein separates Verzeichnis verschieben.
Die Datei-/ und Ordernamen bei dem Bekannten sind chaotisch.


@echo off & setlocal
set LOG=z__Con.log
set SD=D:\00_Test\0_Testordner
del /f /s /q "%LOG%" >nul 2>nul  

::	1
for /r %SD% %%i in (*.odt *.ods) do Call :KAUNT "%%~fi" 1  
pause

::	2
for /r %SD% %%i in (*.odt) do Call :Sub "%%~fi" "%%~ni" "%%~pi" "%%~ni%%~xi" "%%~xi" "%%~di" ".doc" 1  
pause

::	3
FOR /r %SD% %%i in (*.ods) do Call :Sub "%%~fi" "%%~ni" "%%~pi" "%%~ni%%~xi" "%%~xi" "%%~di" ".xls" 1  
pause
goto :EOF

:Sub
set %8=m
set /a m+=1
set DFoil=%~6%~3%~2

echo %m%. Orig-File: %1 >>%LOG%
echo %m%. DestFoil: %DFoil% >>%LOG% & echo. >>%LOG%

::	find identical file" , todo: mv to "D:\00_Result" 
if exist %DFoil%%7 echo %m%. Neu-File:  %DFoil%%~7 >>%LOG% & echo. >>%LOG%
Type NUL>"%DFoil%%7" >>%LOG%  
goto :EOF

:KAUNT
set %2=m
set /a m+=1
echo %m% Orig-File: %1>>%LOG%

GOTO :EOF

Zeile 7 erzeugt (letzte Zeilen):
273 Orig-File: "D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\spread (1).ods"  
274 Orig-File: "D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\spread (31).ods"  
275 Orig-File: "D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\spread (32).ods"  
276 Orig-File: "D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\spread (33).ods"  
277 Orig-File: "D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\spread (34).ods"  
278 Orig-File: "D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\spread (35).ods"  

Zeile 11 erzeugt (letzte Zeilen):
470. Orig-File: "D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\text - Kopie (9).odt"   
470. DestFoil: D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\text - Kopie (9)  
 
471. Orig-File: "D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\text - Kopie.odt"   
471. DestFoil: D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\text - Kopie  
 
472. Orig-File: "D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\text.odt"   
472. DestFoil: D:\00_Test\0_Testordner\E3 zweitt„gig\E4\E5\E6\00  k o m pl e x   4   und E3 zweitt„gig\text  

Zeile 15 erzeugt (letzte Zeilen):
1. Orig-File: "D:\00_Test\0_Testordner\spread (1).ods"   
1. DestFoil: D:\00_Test\0_Testordner\spread (1)  

es hakt bei
set DFoil=%~6%~3%~2


Hat jemand einen Rat
oder einen besseren/kürzeren Ansatz?

Danke im voraus.

Content-Key: 441178

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

Printed on: April 23, 2024 at 14:04 o'clock

Mitglied: 139374
139374 Apr 16, 2019 updated at 20:04:04 (UTC)
Goto Top
oder einen besseren/kürzeren Ansatz?
@echo off
Powershell -Executionpolicy Bypass -NoP -C "dir 'd:\quelle' -File -Recurse -Include '*.ods','*.xls','*.odt'.'*.doc' | group Basename | ?{$_.Count -gt 1} | %%{$_.Group | move-item -destination 'd:\Ziel' -Verbose}"  
Member: robx
robx Apr 17, 2019 at 08:02:29 (UTC)
Goto Top
danke!
ich bekomme den error:
Fehlender Ausdruck nach dem unären Operator "-".  
Bei C:\Users\xxx\Documents\odt__001__Full.ps1:1 Zeichen:2
+ - <<<< Executionpolicy Bypass -NoP -C "dir 'D:\00_Test\0_Testordner' -File -Recurse -Include '*.ods','*.xls','*.odt','*.doc' | group Basename | ?{$_.Count -gt 1} | %%{$_.Group | move-item -destination 'D:\  
00_Test_RESULT' -Verbose}"  
    + CategoryInfo          : ParserError: (-:String) , ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator
das sagt mir leider mom. nichts.
ich werde mich in PS einarbeiten.

Hast Du einen Tip?
Mitglied: 139374
139374 Apr 17, 2019 updated at 08:40:52 (UTC)
Goto Top
Du hast fehlerhaft kopiert oder ein Leerzeichen zwischen Parameter und Dash eingeschmuggelt. Funktioniert hier einwandfrei.
Bedenke das der Code so wie er hier steht nur in einer Batchdatei funktioniert da hier die Prozentzeichen verdoppelt wurden! Für das direkte Ausprobieren auf der Konsole muss aus den doppelten ein einfaches Prozentzeichen gemacht werden.
Member: robx
robx Apr 17, 2019 at 08:58:53 (UTC)
Goto Top
Wie wäre der code für PS 2.0 (sorry)
Mitglied: 139374
Solution 139374 Apr 17, 2019 at 09:02:17 (UTC)
Goto Top
@echo off
Powershell -Executionpolicy Bypass -NoP -C "dir 'd:\quelle' -Recurse -Include '*.ods','*.xls','*.odt'.'*.doc' | ?{!$_.PSIsContainer} | group Basename | ?{$_.Count -gt 1} | %%{$_.Group | move-item -destination 'd:\Ziel' -Verbose}"  
Member: robx
robx Apr 17, 2019 at 09:24:31 (UTC)
Goto Top
klasse. Danke!