Connecting Tech Pros Worldwide Help | Site Map

getting the last index of an array

  #1  
Old October 6th, 2008, 06:07 AM
Newbie
 
Join Date: Oct 2008
Posts: 14
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

Expand|Select|Wrap|Line Numbers
  1. l=filename.split("")
  2.     print 'Name',
  #2  
Old October 6th, 2008, 02:15 PM
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,545

re: getting the last index of an array


Expand|Select|Wrap|Line Numbers
  1. >>> import os
  2. >>> os.path.basename(r'D:\Miscellaneous\FEMA-350.pdf')
  3. 'FEMA-350.pdf'
  4. >>> 
  #3  
Old October 6th, 2008, 05:10 PM
Newbie
 
Join Date: Oct 2008
Posts: 14

re: getting the last index of an array


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.
  #4  
Old October 6th, 2008, 05:55 PM
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,545

re: getting the last index of an array


I don't understand the question. This will print all the file and directory names in the current working directory:
Expand|Select|Wrap|Line Numbers
  1. >> for fn in os.listdir(os.getcwd()):
  2. ...     print fn
  3. ...     
  #5  
Old October 7th, 2008, 09:22 AM
Newbie
 
Join Date: Oct 2008
Posts: 14

re: getting the last index of an array


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$python 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
  #6  
Old October 7th, 2008, 01:53 PM
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,545

re: getting the last index of an array


Quote:
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$python 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:
Expand|Select|Wrap|Line Numbers
  1. import os
  2. for fn in os.listdir('/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA'):
  3.     print fn
  #7  
Old October 8th, 2008, 04:15 AM
Newbie
 
Join Date: Oct 2008
Posts: 14

re: getting the last index of an array


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
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help!! How do I delete part of an array? JLC answers 3 April 11th, 2007 05:20 PM
Request object, ASP 0105 (0x80004005) An array index is out of range. steve_jackson@cox.net answers 4 January 29th, 2007 02:35 PM
Problem retrieving an object from an array and calling a method on the object Jayman777@gmail.com answers 3 October 8th, 2006 06:35 PM
Checking status of an array David P. Jessup answers 3 July 19th, 2005 08:57 AM