Python sys & os draft

Last modified today / Edit on Github
This is a draft, the content is not complete and of poor quality!


import os, sys
import shutil

Copy and move

shutil.copy('/Users/a/file.txt', '/Users/b/file.txt')
# Move a file from /Users/a/file.txt to /Users/b/
# (cannot replace)
shutil.move('/Users/a/file.txt', '/Users/b/')

# Move and replace
shutil.move('/Users/a/file.txt', '/Users/b/file.txt')

Append path to the environnement

sys.path.append('../') # the path of current file's father

Get files' info

# Find location first and then get the path
file = ''
for root, _, files in os.walk(r'D:\python'):
for name in files:
if name == file:
print (os.path.abspath(os.path.join(root, name)))
# List of all files in a path
file_path = '.' # current dir
# The last modification