File Path retrieving problem

music24by7 at gmail.com music24by7 at gmail.com
Wed Feb 25 23:16:39 EST 2009


On Feb 26, 9:03 am, Steve Holden <st... at holdenweb.com> wrote:
> music24... at gmail.com wrote:
> > On Feb 26, 2:35 am, Emile van Sebille <em... at fenx.com> wrote:
> >> Peter Otten wrote:
> >>> Maybe it's about access rights?
> >>> $ mkdir alpha
> >>> $ touch alpha/beta
> >>> $ python -c"import os; print os.path.exists('alpha/beta')"
> >>> True
> >>> $ chmod u-x alpha
> >>> $ python -c"import os; print os.path.exists('alpha/beta')"
> >>> False
> >>> $
> >>> I Don't know how this is handled on Windows...
> >> Here's one way....
>
> >> Microsoft Windows XP [Version 5.1.2600]
> >> (C) Copyright 1985-2001 Microsoft Corp.
> >> C:\>mkdir alpha
> >> C:\>touch alpha\beta  # cygwin at work here...
>
> >> C:\>python -c"import os; print os.path.exists('alpha/beta')"
> >> True
>
> >> C:\>cacls alpha /E /R "Everyone"
> >> processed dir: C:\alpha
> >> C:\>cacls alpha /E /R "Users"
> >> processed dir: C:\alpha
> >> C:\>cacls alpha /E /R "Administrators"
> >> processed dir: C:\alpha
>
> >> C:\>python -c"import os; print os.path.exists('alpha/beta')"
> >> False
>
> > Hi,
>
> > This is the following code which i have used to retrieve the pathname
> > of a filename given by the user
>
> >         filename = self.enText.get() # get the text entered in the
> > text box
> >         if os.path.exists(filename): # checking if the filename
> > exists , had replaced it with os.path.exists(os.path.abspath
> > (filename))
> >             print os.path.abspath(filename)
> >         else:
> >             print "Not found"
>
> > actually i need to list all the files/folders with the given filename
> > alongwith path and store it in an CSV file with index.
>
> > But i am unable to get even a single filepath correctly.
> > Whatever filename i enter the output is as : C:\Python25\WorkSpace
> > \xyz
> > i.e the name i entered is being appended to my workspace and
> > displayed.
> > Guys, i am not able to understand what shall i do here...plz help me
> > out.
>
> Look, we aren't psychic. We can't debug code and directories we can't
> see. Work with us here - give us the information we need to help you.
>
> The actual code. A directory listing? Any error messages?
>
> regards
>  Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC              http://www.holdenweb.com/





Hi Steve,

Following is the code which i have written to display a GUI textbox
and get any name entered by the user and search the path of this
filename and then list it into an CSV file.

For this i initially created an textbox widget and added an button to
it.
Now, i have entered a filename (like NEWS.txt) in the text boz,
as you can see when i press the button i retrieve the text and then
search its filepath.
currently i am printing this filepath on the shell.


from Tkinter import *
import os
from os.path import realpath, exists, abspath
import tkMessageBox
import Tkinter
#import filePath

class GUIFrameWork(Frame):
    """This is the GUI"""

    def __init__(self,master=None):
        """Initialize yourself"""

        """Initialise the base class"""
        Frame.__init__(self,master)

        """Set the Window Title"""
        self.master.title("Enter Text to search")

        """Display the main window"
        with a little bit of padding"""
        self.grid(padx=10,pady=10)
        self.CreateWidgets()

    def CreateWidgets(self):

        self.enText = Entry(self)
        self.enText.grid(row=0, column=1, columnspan=3)



        """Create the Button, set the text and the
        command that will be called when the button is clicked"""
        self.btnDisplay = Button(self, text="Display!",
command=self.Display)
        self.btnDisplay.grid(row=0, column=4)

    def Display(self):
        """Called when btnDisplay is clicked, displays the contents of
self.enText"""
        filename = self.enText.get()
        if os.path.exists(os.path.abspath(filename)):
            print os.path.abspath(filename)
        else:
            print "Not found"
        #tkMessageBox.showinfo("Text", "You typed: %s" %
os.path.abspath(os.path.dirname(filename)))

        #filepath.mydir(self.enText.get())


if __name__ == "__main__":
    guiFrame = GUIFrameWork()
    guiFrame.mainloop()





User Input: NEWS.txt
Output: Not Found (though this file is actually present)




Regards,
Sudhir



More information about the Python-list mailing list