1

I have some link files on windows, then I put them in a folder, I want to rename them as 0 1 2 ... , so windows can sort them automatically.

I tried os.rename('src.txt.link', '0'), but the result is that the "0" file can not be opened.

Is there an another python api to do this?

王王王
  • 127
  • 1
  • 10
  • Link files on Windows usually have an extension of `.lnk` and when you rename the file you need to preserve it because it's how the file type is identified. i.e. `'src.txt.lnk'` -> `'0.lnk'`. – martineau Mar 18 '17 at 02:29
  • Possible duplicate of [Rename Files in Python](http://stackoverflow.com/questions/2759067/rename-files-in-python) – Ken White Mar 18 '17 at 02:37
  • on windows it's not need an extension of .lnk, you can try it – 王王王 Mar 18 '17 at 02:38
  • Of course you need the .lnk extension on the filename. If you think otherwise it's because you have the shell configured to hide extensions. – Eryk Sun Mar 18 '17 at 08:43
  • Actually the system especially hides the extension for .lnk files because `HKLM\Software\Classes\lnkfile` defines the value `NeverShowExt`. If you rename that registry value and change the association of .lnk files to some other ProgId and then back to the `lnkfile` ProgId, you should see the .lnk extension on the names of shell shortcuts. – Eryk Sun Mar 18 '17 at 08:55

1 Answers1

0

You cannot rename a file with extension .lnk. Looks like Windows blocks that operation. Instead i suggest you copy the file with new name, in your case 0.lnk, and then remove the original file.

dismine
  • 575
  • 13
  • 17