How could I get the file name and the permissions to a file as a string? This is on a Linux system.

str function calls the appropriate method of the value to turn it to a string.

os.access("myfilename", os.R_OK)

from Tkinter import *
def fileopenbox(msg=None, title=None, default=None):
    root = Tk()
    root.withdraw()
    f = tkFileDialog.askopenfilename(parent=root,title=title, initialfile=default)
    if not f: return None
    return os.path.normpath(f)

use os.F_OK for exsistence,
os.R_OK for read rights,
os.W_OK for write rights,
os.X_OK for execution rights

james.lu.75491856 What if I want all the permissions just as they're listed using ls -l?

lrwxr--r--
drwxr-w---

You could try to or the permissions with '|'

vegaseat What do you mean?

you need to chmod the file. i think is os.chmod(filname,octal value)

I wrote a linux-like chmod() code snippet once. It contains a function get_mode_by_ls() in the example part. The snippet uses the S_* constants of the stat module.

james.lu.75491856 What if I want all the permissions just as they're listed using ls -l?

import subprocess
v = subprocess.Popen(["ls","-l"])
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.