I am getting the following error in "python" when I try os.rename in Windows, Python 3 (spyder).
os.rename('123456789012345678901234567890123456.jpg', '1234567890123456789012345678901234567.jpg')
FileNotFoundError: [WinError 3] The system cannot find the path specified: '123456789012345678901234567890123456.jpg' -> '1234567890123456789012345678901234567.jpg'
The file name above got 36 characters.
When I try with 35 character filename then I am NOT getting the error and rename works fine.
os.rename('12345678901234567890123456789012345.jpg', '123456789012345678901234567890123456.jpg')
I've also tried with FULL path C:....\filename in the source and target file for rename but it works with the file name till 35 characters (full path it has got 254 characters including file name). When I try with 255 characters (ie., full path including file name with 36 characters), then I am getting Win Error 3. If the file doesn't exists (really), then I got Win Error 2.
I am looking for a generic solution so that I can apply this for all large file named files.
The problem is that windows has a path size limit of 260 characters, when adding the path plus filename. If you move your file closer to the root, it will be renamed just fine.
See this documentation for more information on the subject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With