Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
devwiki:python [2019/01/10 01:38]
ying [re]
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>
Line 752: Line 759:
     elif sys.platform == '​linux2':​     elif sys.platform == '​linux2':​
         try:         try:
-            subprocess.check_call(['​xdg-open', '--', folderPath])+            subprocess.check_call(['​xdg-open',​ folderPath])
         except subprocess.CalledProcessError:​         except subprocess.CalledProcessError:​
             pass # handle errors in the called executable             pass # handle errors in the called executable
Line 786: Line 793:
 subprocess.Popen([r'​D:​\App\Python27\python.exe',​r'​D:​\Dev\Pipeline\PyDesktop\CompFolder\CompFolder.py'​]) subprocess.Popen([r'​D:​\App\Python27\python.exe',​r'​D:​\Dev\Pipeline\PyDesktop\CompFolder\CompFolder.py'​])
 subprocess.Popen([r'​D:​\Dev\Pipeline\PyDesktop\CompFolder\CompFolder.bat'​]) subprocess.Popen([r'​D:​\Dev\Pipeline\PyDesktop\CompFolder\CompFolder.bat'​])
 +# force it to open in new console window instead of inside parent console window
 +subprocess.Popen([r'​D:​\Dev\Pipeline\PyDesktop\CompFolder\CompFolder.bat'​],​ creationflags=subprocess.CREATE_NEW_CONSOLE) ​
  
 # if above method failed because PATH or PYTHONPATH issue, especially when call like above in a mixed python environment like Maya, # if above method failed because PATH or PYTHONPATH issue, especially when call like above in a mixed python environment like Maya,