mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-23 20:11:13 +00:00
fileops
This commit is contained in:
parent
6c1baa7861
commit
5cdf9fd0ea
22
os_shutil_fileops
Normal file
22
os_shutil_fileops
Normal file
|
@ -0,0 +1,22 @@
|
|||
# sr 11/19/2013
|
||||
# common file operations in os and shutil modules
|
||||
|
||||
import shutil
|
||||
import os
|
||||
|
||||
# Getting files of particular type from directory
|
||||
files = [f for f in os.listdir(s_pdb_dir) if f.endswith(".txt")]
|
||||
|
||||
# Copy and move
|
||||
shutil.copyfile("/path/to/file", "/path/to/new/file")
|
||||
shutil.copy("/path/to/file", "/path/to/directory")
|
||||
shutil.move("/path/to/file","/path/to/directory")
|
||||
|
||||
# Check if file or directory exists
|
||||
os.path.exists("file or directory")
|
||||
os.path.isfile("file")
|
||||
os.path.isdir("directory")
|
||||
|
||||
# Working directory and absolute path to files
|
||||
os.getcwd()
|
||||
os.path.abspath("file")
|
Loading…
Reference in New Issue
Block a user