Move files with the os module | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Move files with the os module

How can I move files using the os module without knowing which system the user uses?

30th Oct 2017, 2:15 PM
Tolo
Tolo - avatar
2 Answers
+ 3
Windows has REName, and I believe you can rename across file systems, which causes a move. Linuxes went with the more representative 'mv' (move) with no 'rename' command. On both, this is what happens: * same filesystem [logical rename looks like a move] Just relinks the file reference * different filesystem [physical move with optional rename] Copy, OPTIONAL verify, delete old copy I don't have Windows to test, but I think this is worth checking:: import os print(os.rename.__doc__) Manually: os.read, os.write, os.unlink
30th Oct 2017, 3:44 PM
Kirk Schafer
Kirk Schafer - avatar
+ 2
Thanks
30th Oct 2017, 8:46 PM
Tolo
Tolo - avatar