getting the last index of an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • klia
    New Member
    • Oct 2008
    • 14

    getting the last index of an array

    Hi folks
    i am totally novice to python, that's why i have to learn it for my final year project.

    Any way i have been using a python module for extracting exif data from pictures taken by digital camera. one of the data is extracting the file name of the picture but the file name is stored on an array so, once i call the extraction the whole file name directory will be printed on the terminal which is /home/waseem/my pictures/1.jpg. home can i be able to print only the FILE NAME of the photo which is 1.jpg.

    Thanks in advance

    here's the code

    Code:
    l=filename.split("")
    	print 'Name',
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    [code=Python]>>> import os
    >>> os.path.basenam e(r'D:\Miscella neous\FEMA-350.pdf')
    'FEMA-350.pdf'
    >>> [/code]

    Comment

    • klia
      New Member
      • Oct 2008
      • 14

      #3
      thanks bvdet for you replay

      your example gave me an idea but there you specified the path of the file and the file name but how can i get that without any user input which means the function will know that i am now in this directory and this is file name so, it will extract the file name from the directory and print it out because if i change my module to other directory i have to change in the code you gave me. i hope you got the idea and sorry for the hassle.


      thanks in advance.

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        I don't understand the question. This will print all the file and directory names in the current working directory:[code=Python]>> for fn in os.listdir(os.g etcwd()):
        ... print fn
        ... [/code]

        Comment

        • klia
          New Member
          • Oct 2008
          • 14

          #5
          hey man,

          your code above printed the files in my working directory which i don't need.

          my module works like this
          waseem@Linux:~/Study Related/project1/python modules/EXIFpy_1.0.7$
          this is my directory
          waseem@Linux:~/Study Related/project1/python modules/EXIFpy_1.0.7$py thon myexif.py -q '/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA/IMAG0044.jpg' what i need is how to get the picture name which is IMAG0044.jpg from '/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA/'. this is the directory of my pictures. your first example did the job for a specific picture but i got thousands of pictures i need to extract their names, i can't do that with your first code because it only applicable for one picture.
          i hope you get my point....
          i think my English ain't helping me much here.
          thank you

          Comment

          • bvdet
            Recognized Expert Specialist
            • Oct 2006
            • 2851

            #6
            Originally posted by klia
            hey man,

            your code above printed the files in my working directory which i don't need.

            my module works like this
            waseem@Linux:~/Study Related/project1/python modules/EXIFpy_1.0.7$
            this is my directory
            waseem@Linux:~/Study Related/project1/python modules/EXIFpy_1.0.7$py thon myexif.py -q '/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA/IMAG0044.jpg' what i need is how to get the picture name which is IMAG0044.jpg from '/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA/'. this is the directory of my pictures. your first example did the job for a specific picture but i got thousands of pictures i need to extract their names, i can't do that with your first code because it only applicable for one picture.
            i hope you get my point....
            i think my English ain't helping me much here.
            thank you
            This will list all the file and subdirectory names in your directory:[code=Python]import os
            for fn in os.listdir('/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA'):
            print fn[/code]

            Comment

            • klia
              New Member
              • Oct 2008
              • 14

              #7
              unfourtently, still not the fulfillment i might be extracting many photos at the time and i also might be extracting only and only one photo at the time so,i need the function that will cop with that which will only print the name of the photo that i specify after calling the module python myexif -q '/home/waseem/......./filename.jg without any concern of hom many the photos are(one, two, three, ....)in the terminal, besides if i changed to another photos directory, the above directory in the code need to be changed which i can't do every time i wanna extract the names, date and camera model from photos....in the module aim using, my file name is held up an an array once i call print filename the whole file name directory will be printed out which i don't need if i want to store all that string into a database but i need only to cut out the file name of the directory. my module already know the directory of the file and the file name.


              thank you

              Comment

              Working...