×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    101

    Red face Help with files..

    How can I query a folder and get the file names and extension name of each and print them to screen? I appreciate any help.

    Thanks in advance,
    picuser

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Help with files..

    Quote Originally Posted by picuser View Post
    How can I query a folder and get the file names and extension name of each and print them to screen? I appreciate any help.

    Thanks in advance,
    picuser
    hello picuser

    you can use the listdir method of the os module to get the list of the files inside a directory.

    Code:
    import os
    os.listdir(your directory path)
    hope it helps you

    Regards
    Gaba88

  3. #3
    Wiki Moderators
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,779

    Re: Help with files..

    Quote Originally Posted by picuser View Post
    How can I query a folder and get the file names and extension name of each and print them to screen? I appreciate any help.

    Thanks in advance,
    picuser
    Try this,

    Code:
    import os, codecs
     
    folder="C:\\Python"
    for f in os.listdir(folder):
        print f
        #Or, we can also see which files have a certain beginning or end:
        if(f.startswith('a')):print f
        if(f.endswith('.mp3')):print f
    Pankaj Nathani
    www.croozeus.com

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    101

    Thumbs up Re: Help with files..

    Thanks gaba88 and Croozeus for the reply, it works perfectly.

Similar Threads

  1. A better way to read several Xml Files
    By Fye_08 in forum Mobile Java General
    Replies: 4
    Last Post: 2009-04-22, 09:28
  2. error when browsing files
    By Scolpy in forum Symbian
    Replies: 17
    Last Post: 2008-11-10, 23:24
  3. Problem packaging and deploying files
    By raffaelbechara in forum Symbian
    Replies: 4
    Last Post: 2008-10-24, 14:53
  4. How to enable security to the files on Memory Card
    By manojkumar.m in forum Mobile Java General
    Replies: 1
    Last Post: 2008-10-04, 18:29
  5. missing header files from FP1 SDK & Plug-ins.
    By ruchirvasavada in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2008-09-08, 20:54

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •