getting the last index of an array 
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 - l=filename.split("")
-
print 'Name',
| 
October 6th, 2008, 02:15 PM
|  | Moderator | | Join Date: Oct 2006 Location: Nashville, TN
Posts: 1,545
| | | re: getting the last index of an array - >>> import os
-
>>> os.path.basename(r'D:\Miscellaneous\FEMA-350.pdf')
-
'FEMA-350.pdf'
-
>>>
| 
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.
| 
October 6th, 2008, 05:55 PM
|  | 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: - >> for fn in os.listdir(os.getcwd()):
-
... print fn
-
...
| 
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
| 
October 7th, 2008, 01:53 PM
|  | 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: - import os
-
for fn in os.listdir('/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA'):
-
print fn
| 
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
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,702 network members.
|