WinFuture-Forum.de: Montalich Daten vom Vormonat per Robocopy verschieben - WinFuture-Forum.de

Zum Inhalt wechseln

Nachrichten zum Thema: Entwicklung
Seite 1 von 1

Montalich Daten vom Vormonat per Robocopy verschieben


#1 Mitglied ist offline   lexxx25 

  • Gruppe: Mitglieder
  • Beiträge: 3
  • Beigetreten: 29. August 19
  • Reputation: 0

geschrieben 30. August 2019 - 09:29

Hallo,

ich möchte jeden ersten Montag im Monat aus einem bestimmten Ordern alle Daten vom Vormonat in ein anderes Verzeichnis verschieben und zippen. Hierzu verwende ich eine batch und Robocopy bzw 7zip.

Ich muss dazu sagen, dass das schreiben von Batches jetzt nicht zu meiner täglichen Arbeit gehört und ich mir dies hier in viel kleinarbeit zusammen gegebastelt habe. :)


Hier meine Batch

@echo on
color f1
title Pida Trace Bereinigung

set month=%date:~3,2%

set year=%date:~6%

IF [08]==[%month%] SET /A month=8
IF [09]==[%month%] SET /A month=9

set /a monthx=%month%-1

if %monthx%==1 set monthx=Januar
if %monthx%==2 set monthx=Februar
if %monthx%==3 set monthx=Maerz
if %monthx%==4 set monthx=April
if %monthx%==5 set monthx=Mai
if %monthx%==6 set monthx=Juni
if %monthx%==7 set monthx=Juli
if %monthx%==8 set monthx=August
if %monthx%==9 set monthx=September
if %monthx%==10 set monthx=Oktober
if %monthx%==11 set monthx=November
if %monthx%==12 set monthx=Dezember


mkdir C:\pida\%monthx%_%Year%\

robocopy C:\pida\daten1\ C:\pida\%monthx%_%Year%\ /move /MINAGE:%Year%%month%01 /R:3 /W:5 /LOG+:C:\pida\Log\LOG-%month%_%Year%.txt

C:\Programme\7-Zip\7z.exe a -r C:\pida\Zip\%Monthx%-%year%.zip C:\pida\%monthx%_%Year%\* >C:\pida\Log\7-zip-log.txt


pause



Hier das Ergebnis der Batch



C:\Pida\sandkasten>color f1

C:\Pida\sandkasten>title Pida Trace Bereinigung

C:\Pida\sandkasten>set month=08

C:\Pida\sandkasten>set year=2019

C:\Pida\sandkasten>IF [08] == [08] SET /A month=8

C:\Pida\sandkasten>IF [09] == [8] SET /A month=9

C:\Pida\sandkasten>set /a monthx=8-1

C:\Pida\sandkasten>if 7 == 1 set monthx=Januar

C:\Pida\sandkasten>if 7 == 2 set monthx=Februar

C:\Pida\sandkasten>if 7 == 3 set monthx=Maerz

C:\Pida\sandkasten>if 7 == 4 set monthx=April

C:\Pida\sandkasten>if 7 == 5 set monthx=Mai

C:\Pida\sandkasten>if 7 == 6 set monthx=Juni

C:\Pida\sandkasten>if 7 == 7 set monthx=Juli

C:\Pida\sandkasten>if Juli == 8 set monthx=August

C:\Pida\sandkasten>if Juli == 9 set monthx=September

C:\Pida\sandkasten>if Juli == 10 set monthx=Oktober

C:\Pida\sandkasten>if Juli == 11 set monthx=November

C:\Pida\sandkasten>if Juli == 12 set monthx=Dezember

C:\Pida\sandkasten>mkdir C:\pida\Juli_2019\
Ein Unterverzeichnis oder eine Datei mit dem Namen "C:\pida\Juli_2019\" existiert bereits.

C:\Pida\sandkasten>robocopy C:\pida\daten1\ C:\pida\Juli_2019\ /move /MINAGE:2019801 /R:3 /W:5 /LOG+:C:\pida\Log\LOG-8_2019.txt

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robustes Dateikopieren für Windows
-------------------------------------------------------------------------------

  Gestartet: Donnerstag, 29. August 2019 18:08:52
   Quelle - C:\pida\daten1\
     Ziel - C:\pida\Juli_2019\

    Dateien :
  Optionen: /DCOPY:DA /COPY:DAT /MOVE /R:1000000 /W:30

------------------------------------------------------------------------------

FEHLER: Ungültiger Parameter #4 : "/MINAGE:2019801"

    Einfache Syntax :: ROBOCOPY Quelle Ziel /MIR

             Quelle :: Quellverzeichnis (Laufwerk:\Pfad oder
                       \\Server\Freigabe\Pfad)
               Ziel :: Zielverzeichnis (Laufwerk:\Pfad oder
                       \\Server\Freigabe\Pfad)
               /MIR :: Spiegelt eine vollständige Verzeichnisstruktur.

    Weitere Informationen erhalten Sie über den Befehl "ROBOCOPY /?"


**** Der Befehl "/MIR" kann Dateien sowohl kopieren als auch LÖSCHEN.

C:\Pida\sandkasten>C:\Programme\7-Zip\7z.exe a -r C:\pida\Zip\Juli-2019.zip C:\pida\Juli_2019\*  1>C:\pida\Log\7-zip-log.txt

C:\Pida\sandkasten>rem del /f /s /q C:\pida\Juli_2019

C:\Pida\sandkasten>pause




Wie mir robocopy ja sagt kommt er mit dem Datumsformat als Parameter für MINAGE nicht klar. Hier fehlt offenbar die "0" vor der "8", denn wenn ich

robocopy C:\pida\daten1\ C:\pida\%monthx%_%Year%\ /move /MINAGE:20190801 /R:3 /W:5 /LOG+:C:\pida\Log\LOG-%month%_%Year%.txt


von Hand ausführe funktioniert es.

Kann mir hie rjemand helfen? Ich finde einfach nicht den Ansatz aus der 8 ein 08 zu machen, bzw robocopy dazu zu bringen yyyymdd anstelle von yyyymmdd als Parameter zu aktzeptieren.

Danke

Gruss Lexxx
0

Anzeige



#2 Mitglied ist offline   Shannon 

  • Gruppe: aktive Mitglieder
  • Beiträge: 131
  • Beigetreten: 12. Februar 13
  • Reputation: 11
  • Geschlecht:unbekannt

geschrieben 30. August 2019 - 11:23

probier mal das:

@echo on
color f1
title Pida Trace Bereinigung

set month=%date:~3,2%

set year=%date:~6%


if %month%==01 set monthx=Januar
if %month%==02 set monthx=Februar
if %month%==03 set monthx=Maerz
if %month%==04 set monthx=April
if %month%==05 set monthx=Mai
if %month%==06 set monthx=Juni
if %month%==07 set monthx=Juli
if %month%==08 set monthx=August
if %month%==09 set monthx=September
if %month%==10 set monthx=Oktober
if %month%==11 set monthx=November
if %month%==12 set monthx=Dezember




g.s.
0

#3 Mitglied ist offline   Shannon 

  • Gruppe: aktive Mitglieder
  • Beiträge: 131
  • Beigetreten: 12. Februar 13
  • Reputation: 11
  • Geschlecht:unbekannt

geschrieben 30. August 2019 - 11:31

Halt sorry Monatsname = Monat -1

if %month%==02 set monthx=Januar
if %month%==03 set monthx=Februar
if %month%==04 set monthx=Maerz
if %month%==05 set monthx=April
if %month%==06 set monthx=Mai
if %month%==07 set monthx=Juni
if %month%==08 set monthx=Juli
if %month%==09 set monthx=August
if %month%==10 set monthx=September
if %month%==11 set monthx=Oktober
if %month%==12 set monthx=November
if %month%==01 set monthx=Dezember



g.s.
0

#4 Mitglied ist offline   lexxx25 

  • Gruppe: Mitglieder
  • Beiträge: 3
  • Beigetreten: 29. August 19
  • Reputation: 0

geschrieben 02. September 2019 - 06:41

Hallo,

Danke erstmal für deine rasche Hilfe.

Leider hat das so nicht geklappt.

@echo on
color f1
title Pida Trace Bereinigung

set month=%date:~3,2%

set year=%date:~6%

set /a monthx=%month%-1

if %monthx%==01 set monthx=Januar
if %monthx%==02 set monthx=Februar
if %monthx%==03 set monthx=Maerz
if %monthx%==04 set monthx=April
if %monthx%==05 set monthx=Mai
if %monthx%==06 set monthx=Juni
if %monthx%==07 set monthx=Juli
if %monthx%==08 set monthx=August
if %monthx%==09 set monthx=September
if %monthx%==10 set monthx=Oktober
if %monthx%==11 set monthx=November
if %monthx%==12 set monthx=Dezember


mkdir C:\pida\%monthx%_%Year%\

robocopy C:\pida\daten1\ C:\pida\%monthx%_%Year%\ /move /MINAGE:%Year%%month%01 /R:3 /W:5 /LOG+:C:\pida\Log\LOG-%month%_%Year%.txt

C:\Programme\7-Zip\7z.exe a -r C:\pida\Zip\%Monthx%-%year%.zip C:\pida\%monthx%_%Year%\* >C:\pida\Log\7-zip-log.txt

rem del /f /s /q C:\pida\%monthx%_%Year%

pause



Ergebnis:


C:\Pida\sandkasten>color f1

C:\Pida\sandkasten>title Pida Trace Bereinigung

C:\Pida\sandkasten>set month=09

C:\Pida\sandkasten>set year=2019

C:\Pida\sandkasten>set /a monthx=09-1
Ungültige Zahl. Numerische Konstanten sind entweder dezimale (17),
hexadezimale (0x11) oder oktale (021) Zahlen.
"set" kann syntaktisch an dieser Stelle nicht verarbeitet werden.
C:\Pida\sandkasten>if ==01 set monthx=Januar



ich habe inspiriert durch deine Antwort auch mal folgendes versucht.

@echo on
color f1
title Pida Trace Bereinigung

set month=%date:~3,2%

set year=%date:~6%

IF [08]==[%month%] SET /A month=8
IF [09]==[%month%] SET /A month=9

set /a monthx=%month%-1

if %monthx%==1 set monthx=01
if %monthx%==2 set monthx=02
if %monthx%==3 set monthx=03
if %monthx%==4 set monthx=04
if %monthx%==5 set monthx=05
if %monthx%==6 set monthx=06
if %monthx%==7 set monthx=07
if %monthx%==8 set monthx=08
if %monthx%==9 set monthx=09
if %monthx%==0 set monthx=12


mkdir C:\pida\%monthx%_%Year%\

robocopy C:\pida\daten1\ C:\pida\%monthx%_%Year%\ /move /MINAGE:%Year%%monthx%01 /R:3 /W:5 /LOG+:C:\pida\Log\LOG-%monthx%_%Year%.txt

C:\Programme\7-Zip\7z.exe a -r C:\pida\Zip\%Monthx%-%year%.zip C:\pida\%monthx%_%Year%\* >C:\pida\Log\7-zip-log.txt

rem del /f /s /q C:\pida\%monthx%_%Year%

pause


das funktioniert in soweit, dass ich keine Fehlermeldung bekomme und das script durchläuft. Allerdings kann ich damit nur die Dateien des Vorvormonats? verschieben. Lasse ich in "/MINAGE:%Year%%monthx%01" anstelle vom monthx die Variable "month" wird wieder eine "8" anstelle einer "08" eingefügt und ich lauf wieder in einen Fehler bei robocopy.

lexxx
0

#5 Mitglied ist offline   lexxx25 

  • Gruppe: Mitglieder
  • Beiträge: 3
  • Beigetreten: 29. August 19
  • Reputation: 0

geschrieben 02. September 2019 - 07:25

sorry, mein Fehler... Man sollte auch das richtige kopieren....

@echo on
color f1
title Pida Trace Bereinigung

set month=%date:~3,2%

set year=%date:~6%

set /a monthx=%month%-1


if %month%==01 set monthx=Januar
if %month%==02 set monthx=Februar
if %month%==03 set monthx=Maerz
if %month%==04 set monthx=April
if %month%==05 set monthx=Mai
if %month%==06 set monthx=Juni
if %month%==07 set monthx=Juli
if %month%==08 set monthx=August
if %month%==09 set monthx=September
if %month%==10 set monthx=Oktober
if %month%==11 set monthx=November
if %month%==12 set monthx=Dezember



mkdir C:\pida\%monthx%_%Year%\

robocopy C:\pida\daten1\ C:\pida\%monthx%_%Year%\ /move /MINAGE:%Year%%month%01 /R:3 /W:5 /LOG+:C:\pida\Log\LOG-%month%_%Year%.txt

C:\Programme\7-Zip\7z.exe a -r C:\pida\Zip\%Monthx%-%year%.zip C:\pida\%monthx%_%Year%\* >C:\pida\Log\7-zip-log.txt

rem del /f /s /q C:\pida\%monthx%_%Year%

pause



ergibt...

C:\Pida\sandkasten>color f1

C:\Pida\sandkasten>title Pida Trace Bereinigung

C:\Pida\sandkasten>set month=09

C:\Pida\sandkasten>set year=2019

C:\Pida\sandkasten>set /a monthx=09-1
Ungültige Zahl. Numerische Konstanten sind entweder dezimale (17),
hexadezimale (0x11) oder oktale (021) Zahlen.

C:\Pida\sandkasten>if 09 == 01 set monthx=Januar

C:\Pida\sandkasten>if 09 == 02 set monthx=Februar

C:\Pida\sandkasten>if 09 == 03 set monthx=Maerz

C:\Pida\sandkasten>if 09 == 04 set monthx=April

C:\Pida\sandkasten>if 09 == 05 set monthx=Mai

C:\Pida\sandkasten>if 09 == 06 set monthx=Juni

C:\Pida\sandkasten>if 09 == 07 set monthx=Juli

C:\Pida\sandkasten>if 09 == 08 set monthx=August

C:\Pida\sandkasten>if 09 == 09 set monthx=September

C:\Pida\sandkasten>if 09 == 10 set monthx=Oktober

C:\Pida\sandkasten>if 09 == 11 set monthx=November

C:\Pida\sandkasten>if 09 == 12 set monthx=Dezember

C:\Pida\sandkasten>mkdir C:\pida\September_2019\

C:\Pida\sandkasten>robocopy C:\pida\daten1\ C:\pida\September_2019\ /move /MINAGE:20190901 /R:3 /W:5 /LOG+:C:\pida\Log\LOG-09_2019.txt

 Protokolldatei: C:\pida\Log\LOG-09_2019.txt

C:\Pida\sandkasten>C:\Programme\7-Zip\7z.exe a -r C:\pida\Zip\September-2019.zip C:\pida\September_2019\*  1>C:\pida\Log\7-zip-log.txt

C:\Pida\sandkasten>rem del /f /s /q C:\pida\September_2019

C:\Pida\sandkasten>pause
Drücken Sie eine beliebige Taste . . .



das ganze funktioniert soweit, die richtigen Daten werden verschoben. Allerdings habe ich jetzt das Problem, dass meine Order und Dateibenennung nicht den letzten sondern diesen Monat hat.

Aber auch das lässt sich lösen..:)s.u.


@echo on
color f1
title Pida Trace Bereinigung

set month=%date:~3,2%

set year=%date:~6%

if %month%==01 set monthx=Dezember
if %month%==02 set monthx=Januar
if %month%==03 set monthx=Februar
if %month%==04 set monthx=Maerz
if %month%==05 set monthx=April
if %month%==06 set monthx=Mai
if %month%==07 set monthx=Juni
if %month%==08 set monthx=Juli
if %month%==09 set monthx=August
if %month%==10 set monthx=September
if %month%==11 set monthx=Oktober
if %month%==12 set monthx=November




mkdir C:\pida\%monthx%_%Year%\

robocopy C:\pida\daten1\ C:\pida\%monthx%_%Year%\ /move /MINAGE:%Year%%month%01 /R:3 /W:5 /LOG+:C:\pida\Log\LOG-%month%_%Year%.txt

C:\Programme\7-Zip\7z.exe a -r C:\pida\Zip\%Monthx%-%year%.zip C:\pida\%monthx%_%Year%\* >C:\pida\Log\7-zip-log.txt

rem del /f /s /q C:\pida\%monthx%_%Year%

pause



C:\Pida\sandkasten>color f1

C:\Pida\sandkasten>title Pida Trace Bereinigung

C:\Pida\sandkasten>set month=09

C:\Pida\sandkasten>set year=2019

C:\Pida\sandkasten>if 09 == 01 set monthx=Dezember

C:\Pida\sandkasten>if 09 == 02 set monthx=Januar

C:\Pida\sandkasten>if 09 == 03 set monthx=Februar

C:\Pida\sandkasten>if 09 == 04 set monthx=Maerz

C:\Pida\sandkasten>if 09 == 05 set monthx=April

C:\Pida\sandkasten>if 09 == 06 set monthx=Mai

C:\Pida\sandkasten>if 09 == 07 set monthx=Juni

C:\Pida\sandkasten>if 09 == 08 set monthx=Juli

C:\Pida\sandkasten>if 09 == 09 set monthx=August

C:\Pida\sandkasten>if 09 == 10 set monthx=September

C:\Pida\sandkasten>if 09 == 11 set monthx=Oktober

C:\Pida\sandkasten>if 09 == 12 set monthx=November

C:\Pida\sandkasten>mkdir C:\pida\August_2019\

C:\Pida\sandkasten>robocopy C:\pida\daten1\ C:\pida\August_2019\ /move /MINAGE:20190901 /R:3 /W:5 /LOG+:C:\pida\Log\LOG-09_2019.txt

 Protokolldatei: C:\pida\Log\LOG-09_2019.txt

C:\Pida\sandkasten>C:\Programme\7-Zip\7z.exe a -r C:\pida\Zip\August-2019.zip C:\pida\August_2019\*  1>C:\pida\Log\7-zip-log.txt

C:\Pida\sandkasten>rem del /f /s /q C:\pida\August_2019

C:\Pida\sandkasten>pause
Drücken Sie eine beliebige Taste . . .



das Ganze funktioniert so..

Nu das ganze ins Lifesystem einpflegen und per task scheduler starten lassen..:)

Vielen Dank für deine Hilfe

gruss lexxx

Dieser Beitrag wurde von lexxx25 bearbeitet: 02. September 2019 - 07:33

0

Thema verteilen:


Seite 1 von 1

1 Besucher lesen dieses Thema
Mitglieder: 0, Gäste: 1, unsichtbare Mitglieder: 0