Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
devwiki:python [2019/08/20 21:45]
ying [useful module list]
devwiki:python [2019/12/05 02:23] (current)
ying [OS system operation]
Line 137: Line 137:
 </​code>​ </​code>​
   * rename file or folder <code python>​os.rename(os.path.join(parentPath,​old_name),​ os.path.join(parentPath,​new_name))</​code>​   * rename file or folder <code python>​os.rename(os.path.join(parentPath,​old_name),​ os.path.join(parentPath,​new_name))</​code>​
 +  * move file (always use full path for safe, and always check source and target exist before operation)<​code python>
 +# file move within same drive
 +os.rename("/​sourcePath/​fileName.ext",​ "/​targetPath/​fileName.ext"​)
 +os.replace("/​sourcePath/​fileName.ext",​ "/​targetPath/​fileName.ext"​)
 +# work for folder and file and cross disk drive
 +shutil.move("/​sourcePath/​fileName.ext",​ "/​targetPath/​fileName.ext"​)
 +</​code>​
    
   * system cmds for each os<code python>   * system cmds for each os<code python>