[Tutor] filename comparison

Alan Gauld learn2program at gmail.com
Tue Jan 11 13:47:08 EST 2022


On 11/01/2022 10:34, mhysnm1964 at gmail.com wrote:
> *	Each directory should have both the above two files. 
> *	There can be multiple MP3 and text files in the same directory.
> *	I want to find out which directories do not have a  plot text file
> associated to the already existing mp3 file.
> *	I want to find out which plot text file does not have a mp3 file.
>
Pseudo code:

index = 0

files = sorted(filelist)   # group the names together

while files to process:

      first = files[index]

      if first is not mp3:      # mp3 is missing

            log error

            index +=1

     elif files[index+1] is not txt     # text file is missing

           log other error

          index += 1

     else: index += 2      a pair so step to next mp3


You could use  iterator next() functions instead of indices 
but in this case I think the explicit index is clearer.


> -- 
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>


More information about the Tutor mailing list