Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.lang.python > #3352
| X-Received | by 2002:a05:620a:753:: with SMTP id i19mr17564171qki.357.1592251497704; Mon, 15 Jun 2020 13:04:57 -0700 (PDT) |
|---|---|
| X-Received | by 2002:a25:73c7:: with SMTP id o190mr45722173ybc.117.1592251497547; Mon, 15 Jun 2020 13:04:57 -0700 (PDT) |
| Path | csiph.com!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail |
| Newsgroups | fr.comp.lang.python |
| Date | Mon, 15 Jun 2020 13:04:57 -0700 (PDT) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | google-groups.googlegroups.com; posting-host=84.102.203.234; posting-account=Ju7EhgkAAADdlXTVvirgIqvqECGFKHtr |
| NNTP-Posting-Host | 84.102.203.234 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <356860d9-d583-4b5c-9248-24ea6d8ca0fdo@googlegroups.com> (permalink) |
| Subject | boucle dans fonction récursive... |
| From | sideley@yahoo.com |
| Injection-Date | Mon, 15 Jun 2020 20:04:57 +0000 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | quoted-printable |
| Xref | csiph.com fr.comp.lang.python:3352 |
Show key headers only | View raw
Bonjour,
Je programme une petite routine de copie récursive de fichiers qui consiste à déplacer tous les fichiers dans une arborescence vers un autre endroit. Il se trouve que la boucle <for...in> a un comportement inattendu: si le premier sous répertoire (de premier niveau dans l'arborescence) obtenu par listdir() est vide (ou devenu vide après le déplacement de son contenu) alors il s'arrête, Il n'y a pas de passage à l'élément souvent du répertoire. Avez vous une explications ?
J'utilise WinPy 3.7.7. Ci dessous les lignes de codes:
import os, shutil, pathlib
def copie(dossier,rep_dest):
contenu_rep = os.listdir(dossier)
for elm in contenu_rep:
chemin = dossier + '/' + elm
if os.path.isdir(chemin):
dossier = chemin
copie(dossier ,rep_dest)
elif os.path.isfile(chemin) and (dossier != rep_dest):
shutil.move(chemin, rep_dest)
def prog ():
dossier = input('Entrez le répertoire à scanner ')
rep_dest = input('Rép destinataire ? ')
copie(dossier,rep_dest)
print ('\n Fait')
return 1
Back to fr.comp.lang.python | Previous | Next — Next in thread | Find similar
boucle dans fonction récursive... sideley@yahoo.com - 2020-06-15 13:04 -0700
Re: boucle dans fonction récursive... Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2020-06-15 23:56 +0200
Re: boucle dans fonction récursive... Artis Sideley <sideley@yahoo.com> - 2020-06-15 15:28 -0700
Re: boucle dans fonction récursive... Pierre Maurette <maurette.pierre@free.fr> - 2020-06-16 07:15 +0200
csiph-web