title: How to rename filename in Arabic in Python
body: <p>I have a script to rename folder and file name from English to another language.  So far this script work well for language reading from left to right.  However, when I run this script on a language reading from right to left (e.g. Arabic), I run into an:</p>
  
  <pre><code>errorFileExistsError: [WinError 183] Cannot create a file when that file already exists
  </code></pre>
  
  <p>My folder structure looks like this:</p>
  
  <pre><code>C:\Users\ABC\Desktop\Template\Report Element Snippets\Review. 
  </code></pre>
  
  <p>Inside the Review folder, I have a file called Blue Review Note.xml.  The full file path of this xml file should be </p>
  
  <pre><code>C:\User\ABC\Desktop\Template\Report Element Snippets\Review\Blue Review Note.xml
  </code></pre>
  
  <p>I will need to rename the Report Element Snippets and Review folders first then run another loop to rename the xml file to Arabic.</p>
  
  <p>The code to rename the xml file is:</p>
  
  <pre><code>os.rename(os.path.join(dirpath,file)
  os.path.join(dirpath,newfname))
  </code></pre>
  
  <p>The problem I could see from tracing the print out of the path is that <code>os.path.join(dirpath,file)</code> give me:</p>
  
  <pre><code>C:\Users\ABC\Desktop\Template\تقرير قصاصات العنصر\إعادة النظر\Blue Review Note. xml
  </code></pre>
  
  <p>where <code>إعادة النظر</code> is Review and <code>تقرير قصاصات العنصر</code> is Report Element Snippets</p>
  
  <p>but <code>os.path.join(dirpath,newfname)</code> give me: </p>
  
  <pre><code>C:\Users\ABC\Desktop\Template\تقرير قصاصات العنصر\إعادة النظر\ملاحظة مراجعة باللون الأزرق.xml
  </code></pre>
  
  <p><code>ملاحظة مراجعة باللون الأزرق.xml</code> is for Blue Review Note.xml</p>
  
  <p>As you can see, the join statement has split the ملاحظة مراجعة باللون<code>الأزرق.xml</code> into 2 parts in the full path.  The <code>ملاحظة مراجعة</code> bit is not put in at the starting of the Arabic path and leave the file name as باللون الأزرق.xml but it doesn't have the \ to separate the xml file name with تقرير قصاصات العنصر folder.  To me the paths between before and after rename of the xml file are different hence Python can't apply the rename on the folder. </p>
  
  <p>I just wonder has anyone has this issue before when working with Arabic file name?</p>