> For the complete documentation index, see [llms.txt](https://lifelong-learning.gitbook.io/pythonjourney/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lifelong-learning.gitbook.io/pythonjourney/easy-and-useful/rename-files.md).

# Rename files

## Task description

* In a file folder, I have lots of files whose name are meaningless code, so I need to rename them.
* If the filename includes no chinese in it, then convert it to number, ie, 1,2,3...
* If the filename includes chinese, then don't change the name.&#x20;

  **Anatomy of task**
* Locate the file folder I want to make changes.
* Read filenames->judge it includes chinese or not->if not, then rename the file

## Difficulties

* **I really should learn about 're'.** Typical error on Windows because the default user directory is C:\user\\, so when you want to use this path as an string parameter into a Python function, you get a Unicode error, just because the \u is a Unicode escape. Any character not numeric after this produces an error.
* os.rename(src,dst) should be abusolute path file not relative, so add :

  `os.rename(os.path.join(directory,filename),os.path.join(directory,str(i)+'.jpg'))`

## Code

[Github code link](https://github.com/ShakalakaB/Python_journey_code/blob/master/easy%26useful/rename_files.py)
