I'm looking throug the documentation at python.org for modules and functions allow me to do basic operations on in a Linux file system. I need to do simple things like list the file and folders in a directory 'ls' and change director 'cd'. I found these two pages that looked promesing but I still didn't fine what I was looking for. Any ideas?

http://docs.python.org/3/library/shutil.html#directory-and-files-operations

http://docs.python.org/3/library/os.path.html

Recommended Answers

All 3 Replies

Python has functions that deal with that stuff - in an operating system neutral manner. RTFM... Or do some simple Google searches! I just did, and came up with a bunch of links to stuff that tells me how to do this stuff.

I need to do simple things like list the file and folders in a directory 'ls' and change director 'cd'. I found these two pages that looked promesing but I still didn't fine what I was looking for. Any ideas?

Maybe you need to broaden your Python knowledge,because this is basic stuff when working with files and folders in Python.

list the file and folders os.listdir(), glob.glob() or os.walk()
os.walk() will recursively walk a directory,means that it will find all subfolders and files.

change director 'cd' os.chdir(path)
os.getcwd() # Returns the current working directory
os.chdir('/path/to/directory') Change the current working directory to 'path/to/directory'.
Also accepts bash commands like '..' and '/'.

Thanks snippsat.

rubberman, I posted two links showing that I did in fact attempt to RTFM!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.