bonjour,
j'ai un fichier qui se trouve dans un dossier, et dont j'aimerai apres copie dans un autre dossier ajouter un prefixe .
le soucis que se pose ,c'est que le nommage ne se fait pas, la copie est bien faite.
la copie se trouve dans une boucle car j'aimerai qu'une fois que le fichier copié est un premier prefixe , puis une autre copie se lance etd' avoir un autre prefixea ce second fichier.
pour le moment la boucle est en attente car effectivement je n'arrive pas a avoir le nomage du 1er fichier.
j'espère avoir été assez clair
j'espère que vous pourrez m'aider.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 import os import glob import fnmatch import shutil source_pth = os.path.abspath("R:/DIVERS/IN/") source = os.listdir(source_pth) rep = "R:\\DIVERS\\A" select = "*.mov" noms = os.listdir(rep) i = 0 while i < 3: for fi in source: if fi.endswith(".mov"): shutil.copy(os.path.join("R:/DIVERS/IN", fi), rep) for nom in noms: ch = os.path.join(rep,nom) if os.path.isfile(fi) and fnmatch.fnmatch(nom,select): os.rename(ch, os.path.join(rep, "truc_"+ nom)) ch = os.path.join(rep,nom) if os.path.isfile(fi) and fnmatch.fnmatch(nom,select): os.rename(ch, os.path.join(rep, "autre_"+ nom))
merci d'avance
Partager