Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Jianling Fan Newsgroups: comp.lang.python Subject: Re: about special characters Date: Sat, 30 Apr 2016 12:13:51 -0600 Lines: 137 Message-ID: References: <572403de$0$1601$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de /zPPbM7FfQ2oy3zJkiSOIA8GyKVDKn22qVlL8FyPFuRw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'win32': 0.03; 'sys': 0.05; '__name__': 0.07; 'filename': 0.07; 'filenames': 0.07; 'cc:addr:python-list': 0.09; "%s'": 0.09; 'filename,': 0.09; 'filename.': 0.09; 'skip:" 80': 0.09; 'src': 0.09; 'src,': 0.09; 'subject:characters': 0.09; 'received:209.85.218': 0.10; 'python': 0.10; '2.7': 0.13; 'def': 0.13; 'ignore': 0.14; 'everyone,': 0.15; "'__main__':": 0.16; '2.7.2': 0.16; '2016': 0.16; '236,': 0.16; 'dest': 0.16; 'dest)': 0.16; 'names?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sync': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.16; 'directory.': 0.18; 'version.': 0.18; '>>>': 0.20; 'windows': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '"",': 0.22; 'os,': 0.22; 'problem:': 0.22; 'trying': 0.22; 'cc:no real name:2**0': 0.22; 'am,': 0.23; 'bit': 0.23; 'sat,': 0.23; 'import': 0.24; '(most': 0.24; 'header :In-Reply-To:1': 0.24; 'script': 0.25; 'skip:" 20': 0.26; 'error': 0.27; 'skip:# 10': 0.27; 'question': 0.27; 'message- id:@mail.gmail.com': 0.27; 'skip:( 20': 0.28; '"no': 0.29; '50,': 0.29; 'path,': 0.29; 'url:mailman': 0.30; 'code': 0.30; 'skip:[ 10': 0.31; 'post': 0.31; 'another': 0.32; 'good.': 0.32; 'problem': 0.33; 'source': 0.33; 'url:python': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'traceback': 0.33; 'url:listinfo': 0.34; "skip:' 20": 0.34; 'file': 0.34; 'skip:d 20': 0.34; 'received:google.com': 0.35; 'path': 0.35; 'but': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'done.': 0.37; 'list.': 0.37; 'received:209': 0.38; 'delete': 0.38; 'names': 0.38; 'files': 0.38; 'copying': 0.38; 'skip:o 20': 0.38; 'skip:e 20': 0.39; 'url:mail': 0.40; 'some': 0.40; 'your': 0.60; 'above,': 0.63; 'more': 0.63; 'different': 0.63; 'our': 0.64; 'between': 0.65; '20,': 0.66; 'here': 0.66; 'special': 0.73; 'yourself': 0.73; '[error': 0.84; 'again!': 0.84; 'greek': 0.84; 'latin': 0.84; 'shoes.': 0.84; '74,': 0.93; 'imagine': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-transfer-encoding; bh=uSHwyr6MUALOTrJeanyCJRM41mHmvS82W5PmFPZ3f68=; b=FEJ2t+8370sea1f36MamXQ1cHmSkIwVadr7tbl2CWNl06+JzrElpPWFO6fWHYjZj5v AfYQfsb7Z7L/lLHUuHLBvIpKXyNpI3N31qycVKSFtcQI4r60M+72xWPo5tvtghiyRz9a M6/V/jl9M4TAvbJ1Pi6nYDbRe6D9hzRJ31XwjGPcFt6TwqoS0pRZduR2ZHZsmWi1wkpM Do8RZ06bmKQQDN57Imrmllid5/PbyCzy/qs3XhsArPENPpAOQ8EfH9DGENg0F54hporS 96yX5cXsYbopPcsa6ysOfyBl0dstbB4L/SF5E3Kg2btB0QiYIP41XHhGoWgM8FpJTBYH GmSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-transfer-encoding; bh=uSHwyr6MUALOTrJeanyCJRM41mHmvS82W5PmFPZ3f68=; b=aKdokPTi/X0nuoJZ7ct2mVfwYbJDYdeH/F6cEaEDTy5RzKPxiSNruAY1aa0W+ZiGtU s6lB4w8HtpU9HrsqTP3Y4QGX/NxsSpaWe9TE++AjkRnffmCBG4i+r1u+wt9mAksgpu/Q rcwiH0U0ykDgLezy5diZZzADMziuOpKQ/sGEK1K4e8nsZIRalCVNTaeLxvKaDXkldcHP +C7/URfd1gWMPKPv76pbocf3CHYWxeJZBUXkKdvdU45mgAGskH1sh1DP89vM1/rXdFdX XrQyNds1LvWmdzX4f3lUZGIJTdqMrGh4PcOU60kYvCXhRSN+LjlLmx7/Tjf1fJs6iRo5 jZgw== X-Gm-Message-State: AOPr4FUDBIUslk3Ox3p+4Ayb0y6PgGFVJVTEy31KozuLqZFgLX0M4UpwdM9fIv0MwgCnWmObJIisJXNG/TAXCw== X-Received: by 10.202.184.6 with SMTP id i6mr12268823oif.76.1462040031648; Sat, 30 Apr 2016 11:13:51 -0700 (PDT) In-Reply-To: <572403de$0$1601$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <572403de$0$1601$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:107920 Hello everyone, Thanks very much for all your replies and sorry for the inconvience. This is my first time to post question in this list. I am using python 2.7 in Windows 7 Enterprise version. Here is the the filename that cause the problem: "Decock-2013-On the potential of =CE=B418O and =CE=B415N.pdf" When I delete the "=CE=B4" in the filename, the script works good. Here is the output: Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> runfile('P:/sync.py', wdir=3D'P:') Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitec= ustomize.py", line 699, in runfile execfile(filename, namespace) File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitec= ustomize.py", line 74, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc) File "P:/sync.py", line 50, in sync_files(src, dest) File "P:/sync.py", line 43, in sync_files sync(dir_cmp) File "P:/sync.py", line 20, in sync shutil.rmtree(f_right) File "C:\Python27\lib\shutil.py", line 236, in rmtree onerror(os.listdir, path, sys.exc_info()) File "C:\Python27\lib\shutil.py", line 234, in rmtree names =3D os.listdir(path) WindowsError: [Error 3] The system cannot find the path specified: 'P:/mystuff\\Decock-2013-On the potential of d18O and d15N.pdf/*.*' Here is my code to do this work: I am using this script to sync my files between different disks. #coding=3Dutf-8 import filecmp, shutil, os, sys SRC =3D r'C:/Disk/mystuff' DEST =3D r'P:/mystuff' IGNORE =3D ['Thumbs.db'] def get_cmp_paths(dir_cmp, filenames): return ((os.path.join(dir_cmp.left, f), os.path.join(dir_cmp.right, f)) for f in filenames) def sync(dir_cmp): for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.right_only): if os.path.isfile(f_right): os.remove(f_right) else: shutil.rmtree(f_right) print('delete %s' % f_right) for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.left_only+dir_cmp.diff_files): if os.path.isfile(f_left): shutil.copy2(f_left, f_right) else: shutil.copytree(f_left, f_right) print('copy %s' % f_left) for sub_cmp_dir in dir_cmp.subdirs.values(): sync(sub_cmp_dir) def sync_files(src, dest, ignore=3DIGNORE): if not os.path.exists(src): print('=3D =3Db Please check the source directory was exist') print('- -b Sync file failure !!!') return if os.path.isfile(src): print('#_# We only support for sync directory but not a single file,one file please do it by yourself') print('- -b Sync file failure !!!') return if not os.path.exists(dest): os.makedirs(dest) dir_cmp =3D filecmp.dircmp(src, dest, ignore=3DIGNORE) sync(dir_cmp) print('^_^ Sync file finished!') if __name__ =3D=3D '__main__': src, dest =3D SRC, DEST if len(sys.argv) =3D=3D 3: src, dest =3D sys.argv[1:3] sync_files(src, dest) Thanks again! On 29 April 2016 at 19:01, Steven D'Aprano wrote: > On Sat, 30 Apr 2016 09:33 am, Jianling Fan wrote: > >> Hello everyone, >> >> I am trying to use python 27 copying some of my folders and files to >> another directory. >> My code works good for other files but I have some problem to copy >> files that have some special characters in the filename. like >> filenames contain Greek "=CE=B4" or latin "=C5=A1". >> it always gave a error that "No such file or directory:" >> >> Any help will be appreciate! > > Please put yourself in our shoes. Read your message above, and, imagine t= hat > you know NOTHING else about your program than what you write above. What > answer would you give? > > Please tell us what you have actually done. How do you copy the files? Ho= w > do you enter the file names? What OS are you using? > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list --=20 Jianling Fan =E6=A8=8A=E5=BB=BA=E5=87=8C