As long as you're in learning mode, allow me to point out that your examples will fail with filenames that (as is all too common) contain whitespace.