The regular file opener with open() as fh will open up the file and place it as a handle in fh, once you call. This will print a files contents every time it's changed. #= Here's an example where you could interact with the process: #= ('Hey you!\n') #= () while run.poll() = None: Run = Popen( 'open -t ' + abspath(expanduser( '~/') + '/example.txt'), shell= True, stdout=PIPE, stdin=PIPE, stderr=STDOUT) erm), here's a Popen approach: from subprocess import Popen, PIPE, STDOUT Print( 'File',fname, 'was last modified at',modtime)Īnd if the time differs from your last check, well then do something cool with it.įor instance, you have these libraries for Python to work with:Īnd MANY more, so instead of opening an external application as your first fix, try opening them via Python and modify to your liking instead, and only as a last resort (if even then) open external applications via Popen.īut since you requested it (sort of. Modtime = ctime(getmtime(abspath(root + '/' + fname))) If it's tracking/catching updates on a file you want from time import ctimeįrom os.path import getmtime, expanduser, abspathįor root, dirs, files in walk(expanduser( '~/')): I honestly can't remember which of the two opens the file as-is from disk ( open() or os.open()) but one of them makes your data look like garbage and sometimes you just get the pointer to the decompression pipe (giving you like 4 bytes of data even tho the text-file is hughe). txt file in OSX for instance normally the text-editor pops up and what it does is call for a os.open() instead of accessing it on a lower level which lets OSX middle layers do disk-area|decompression pipe|file-handle -> Texteditor but if you access the file-object on a lower level you'll end up opening the disk-area where the file is stored and if you print the data you'll get garbage because it's not the data you'd expect. This can literately ruin your day unless you know about it (been there, had the headache.
txt file which under Windows would be considered a "plain text-file" is actually a compressed data-stream under OSX because OSX tries to be "smart" about the storage space. Take note of OSX file-handling tho, the IO is a bit different depending on the filetype.įor instance, a. Answer #1: from os.path import baspath, expanduserįilepath = abspath(expanduser( "~/") + '/Downloads/DeletingDocs.txt')