[Tutor] Using subprocess on a series of files with spaces

Steven D'Aprano steve at pearwood.info
Fri Aug 1 00:43:28 CEST 2014


Oops, a silly bug:

On Fri, Aug 01, 2014 at 08:35:34AM +1000, Steven D'Aprano wrote:

> directory = '/path/to/the/directory'
> for track, filename in enumerate(os.listdir(directory), 1):
>     pathname = os.path.join(directory, filename)
>     subprocess.call(['ffmpeg', '-i', filename, str(track)+'.mp3'])

That should be pathname, of course:

    subprocess.call(['ffmpeg', '-i', pathname, str(track)+'.mp3'])

Also, be aware that the order of files coming from listdir is not 
guaranteed to be sorted in any specific fashion, so if you're renaming 
files like "3 blah blah blah.flac" to "7.mp3" you may end up a little 
confused :-)


-- 
Steven


More information about the Tutor mailing list