Minitool mit grafischer Oberfläche - Datein umbennen mit Input aus aus Excel file

Du hast eine Idee für ein Projekt?
Antworten
Benutzeravatar
__blackjack__
User
Beiträge: 14305
Registriert: Samstag 2. Juni 2018, 10:21
Wohnort: 127.0.0.1
Kontaktdaten:

Wobei `filename` besser `path` hiesse, denn vor dem ``if`` ist noch nicht klar ob es ein *Datei*name ist. Stem + Suffix ist umständlich für `name` und `filename.name` sieht irgendwie komisch aus. Zudem hat `Path` mit `with_name()` eine Methode um einen Pfad mit einem anderen Namen zu erstellen was sich ganz nett liest.

Ungetestet:

Code: Alles auswählen

#!/usr/bin/env python3
from pathlib import Path

QUELLPFAD = Path("E:/Fileordner")


def main():
    if not QUELLPFAD.exists():
        print("Fehler Pfad existiert nicht")
    else:
        print("Pfad gefunden")
        for path in QUELLPFAD.iterdir():
            print(path)
            if path.is_file():
                path.rename(path.with_name("text" + path.name))


if __name__ == "__main__":
    main()
„Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.“ — Brian W. Kernighan
Antworten