×

Discussion Board

Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22

Thread: File Search

  1. #16
    Regular Contributor
    Join Date
    May 2008
    Posts
    88

    Re: File Search

    Hey,
    Srry to bother you...but how to do that...
    Rishabh

  2. #17
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: File Search

    Code:
    import os, appuifw
    
    
    def findfile(folder, file_extension):
        p=[]
        stack = [(folder, os.listdir(folder))]
        while stack:
            folder, names = stack[-1]
            while names:
                name = names.pop()
                path = os.path.join(folder, name)
                if os.path.isfile(path):
                    if name.lower().endswith(file_extension):
                        p.append(path)
                elif os.path.isdir(path):
                    stack.append((path, os.listdir(path)))
                    break
            else:
                stack.pop()
        return p
    
    # Ask for the extension of the file to search for
    file_extension = appuifw.query(u'Enter file extension', 'text')
    
    # Specify the folder to look in; file extension is used in lower case for
    # case insensitive comparison
    path = findfile('C:\\', file_extension.lower())
    
    # Display the path or error message if not found
    if path is None:
        appuifw.note(u'Not found')
    else:
        for i in path:
    	print i

  3. #18
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: File Search

    Yes, very good.

    We could also use os.path.splitext() to extract the extension from a file name, like this:

    Code:
    if os.path.splitext(name)[-1].lower() == file_extension:
    The advantage is that we don't have to lowercase the whole filename anymore .

  4. #19
    Regular Contributor
    Join Date
    May 2008
    Posts
    88

    Re: File Search

    Hi,
    If I know the path of a particular file and I wanna check if its thr or not wht should I use.It would be fast to directly check it rather than searching in all the directories...
    Rishabh

  5. #20
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: File Search

    Not that I want to discourage you from asking questions, but after all the examples and explanations in this thread couldn't you do this simple form by yourself?

    Anyway, here's the code:
    Code:
    import os, appuifw
    
    
    #Enter the path of the file along with the file name
    #Like C:\\Data\\sounds.mp3
    complete_path=appuifw.query(u"Enter complete file path", "text")
    
    #Check if the file exists
    if(os.path.isfile(complete_path)):
    	appuifw.note(u"File is there")
    else:
    	appuifw.note(u"File is not there")
    Last edited by bogdan.galiceanu; 2008-06-26 at 17:16. Reason: fixed typo

  6. #21
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,777

    Re: File Search

    Rishabh your questions are more inclined towards core Python rather than PyS60.

    I suggest you to go through the Python documentation and tutorials.

    Best Regards,
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  7. #22
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: File Search

    Or just use the os.path.exists() function.
    Code:
    if os.path.exists(complete_path):
        appuifw.note(u'Is there')
    else:
        appuifw.note(u'Is not there')
    And like croozeus said, try to find the answers yourself first. It's much more fun if you can say that you did something yourself.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Carbide Build PKG file to SISX - Phone says: "Can't Install"
    By mikedeklerk in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 6
    Last Post: 2009-05-19, 08:23
  2. Tranfering file by bluetooth
    By hassan83 in forum Python
    Replies: 5
    Last Post: 2008-04-18, 17:01
  3. Help needed with a 3gp file...
    By joedoe_1981 in forum Streaming and Video
    Replies: 0
    Last Post: 2007-07-18, 18:58
  4. Search for a file
    By Amilael in forum Symbian C++
    Replies: 12
    Last Post: 2006-11-10, 08:26
  5. Series 60 SDK Appwizard on windows xp
    By moonjoor in forum Symbian Tools & SDKs
    Replies: 15
    Last Post: 2003-12-24, 10:22

Posting Permissions

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