Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'encoded': 0.07; 'rename': 0.07; 'arguments': 0.09; 'filename': 0.09; 'filenames': 0.09; 'try:': 0.09; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'guys,': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'posted.': 0.16; 'utf8': 0.16; 'wrote:': 0.18; 'skip:f 30': 0.19; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'originally': 0.30; 'code': 0.31; 'skip:= 40': 0.31; 'though.': 0.31; 'skip:b 30': 0.33; 'subject:from': 0.34; 'subject: (': 0.35; 'except': 0.35; 'prepare': 0.35; 'doing': 0.36; 'wrong': 0.37; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'happen': 0.63; 'today': 0.64; 'here': 0.66; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; '8bit%:100': 0.72; 'greek': 0.84; 'reply- to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=KrN0hwmN c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=oyR3mlnJdzkA:10 a=AdgiQdVXbpoA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=uw23S90zXSUA:10 a=kuh5_Pv0IQJqnivzJFIA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett:2500 Date: Sat, 08 Jun 2013 18:48:46 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Changing filenames from Greeklish => Greek (subprocess complain) References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370713724 news.xs4all.nl 15998 [2001:888:2000:d::a6]:58834 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47394 On 08/06/2013 17:53, Νικόλαος Κούρας wrote: > Sorry for th delay guys, was busy with other thigns today and i am still reading your resposes, still ahvent rewad them all just Cameron's: > > Here is what i have now following Cameron's advices: > > > #======================================================== > # Collect filenames of the path directory as bytes > path = b'/home/nikos/public_html/data/apps/' > filenames_bytes = os.listdir( path ) > > for filename_bytes in filenames_bytes: > try: > filename = filename_bytes.decode('utf-8) > except UnicodeDecodeError: > # Since its not a utf8 bytestring then its for sure a greek bytestring > > # Prepare arguments for rename to happen > utf8_filename = filename_bytes.encode('utf-8') > greek_filename = filename_bytes.encode('iso-8859-7') > > utf8_path = path + utf8_filename > greek_path = path + greek_filename > > # Rename current filename from greek bytes --> utf8 bytes > os.rename( greek_path, utf8_path ) > ========================================== > > I know this is wrong though. Yet you did it anyway! > Since filename_bytes is the current filename encoded as utf8 or greek-iso > then i cannot just *encode* what is already encoded by doing this: > > utf8_filename = filename_bytes.encode('utf-8') > greek_filename = filename_bytes.encode('iso-8859-7') > Try reading and understanding the code I originally posted.