Results 1 to 32 of 32

Thread: List a special directory in an OpenFileDialog?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    List a special directory in an OpenFileDialog?

    Hi, how do I list a directory with the extension .luaproj in an OpenFileDialog box?

    When the user double clicks on their .luaproj file or clicks once then open, the application will do whatever I tell it's meant to do with the file.

    I just need to know how to display it and kind of open it with an OFDB.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: List a special directory in an OpenFileDialog?

    vb Code:
    1. Dim ofd As New OpenFileDialog()
    2. ofd.Filter = "Description here (*.luaproj)|*.luaproj"
    3.  
    4. if ofd.showdialog 'etc

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: List a special directory in an OpenFileDialog?

    Doesn't work

  4. #4
    Fanatic Member
    Join Date
    Oct 2003
    Posts
    1,005

    Re: List a special directory in an OpenFileDialog?

    1) Drop a Dialog on your form

    2) Use this code in a button/menu

    Code:
    'set variables
            Dim OpenDlg As New OpenFileDialog
            OpenDlg.Title = "Add Database Path"
            OpenDlg.Filter = "Access Databases (*.mdb;*.mde)|*.mdb;*.mde"
            OpenDlg.InitialDirectory = "C:\Windows\System32\System.mdw"
            OpenDlg.CheckPathExists = True
            OpenDlg.CheckFileExists = True
    
            'prompt user
            If OpenDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
                If Len(OpenDlg.FileName) > 0 Then
                    'return result
                    'EXECUTE CODE HERE
                Else
                    MessageBox.Show("You have not selected a file name. Please try again.", "No Filename Selected", MessageBoxButtons.OK)
                End If
            Else
                Exit Sub
            End If

  5. #5
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: List a special directory in an OpenFileDialog?

    The OP specifically asked for '.luaproj' files, not mdb files...

    Why did paul's code not work? It should work perfectly fine. Do some research on the OpenFileDialog control and especially it's "Filter" property. This property allows you to set the filter that you can usually select in the bottom-right corner. If you set the filter such as paul did in his code, you will only see files that have a '.luaproj' extension.

  6. #6
    Fanatic Member
    Join Date
    Oct 2003
    Posts
    1,005

    Re: List a special directory in an OpenFileDialog?

    I just copy and pasted from one of my apps.

    You have to go and change the file extensions yourself.
    You can edit the code you know...

    It was just an example.


  7. #7
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: List a special directory in an OpenFileDialog?

    Quote Originally Posted by epixelman
    1) Drop a Dialog on your form

    2) Use this code in a button/menu

    Code:
    'set variables
            Dim OpenDlg As New OpenFileDialog
            OpenDlg.Title = "Add Database Path"
            OpenDlg.Filter = "Access Databases (*.mdb;*.mde)|*.mdb;*.mde"
            OpenDlg.InitialDirectory = "C:\Windows\System32\System.mdw"
            OpenDlg.CheckPathExists = True
            OpenDlg.CheckFileExists = True
    
            'prompt user
            If OpenDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
                If Len(OpenDlg.FileName) > 0 Then
                    'return result
                    'EXECUTE CODE HERE
                Else
                    MessageBox.Show("You have not selected a file name. Please try again.", "No Filename Selected", MessageBoxButtons.OK)
                End If
            Else
                Exit Sub
            End If
    Why do you tell him to drop a dialog on the form then use your code when your code creates a dialog and never uses the one on the form?
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: List a special directory in an OpenFileDialog?

    Sorry for the late reply, it'sbeen a busy week.

    I need to show a directory/folder that has the extension .luaproj, not files with .luaproj.

  9. #9
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: List a special directory in an OpenFileDialog?

    Do folders have extensions..? I know you can have folders with a "." in their name but that doesn't make them extensions, or am I completely wrong here?

    Either way, I don't think you can do this without creating your own OpenFileDialog... It might be possible with some API calls but I doubt it...

    Still, I have never heard of this before so again I might be completely wrong.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: List a special directory in an OpenFileDialog?

    In my application, I prefer for folders to be self contained because they hold everything todo with the project, I don't like the thought of project folders like Visual Studio makes either.

  11. #11
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: List a special directory in an OpenFileDialog?

    Here you can copy this exactly as long as you add a button called Button1:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         'on the click event of Button 1 *You must first add button 1 if you were to use this exact code* :
    3.         Dim mydialog As New OpenFileDialog
    4.         With mydialog
    5.             .Title = "Open Dialog"
    6.             .InitialDirectory = (Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
    7.             .Filter = "luaproj files|*.luaproj"
    8.             If .ShowDialog = Windows.Forms.DialogResult.OK Then
    9.                 'Here you can do what you want once the users selects a file,
    10.                 'to reference the selected files path use .filename
    11.                 'Here is an example of what you can do. I will display the text in
    12.                 'the .luaproj file, in a messagebox.
    13.                 MsgBox(IO.File.ReadAllText(.FileName))
    14.             End If
    15.         End With
    16.     End Sub

    Also i am guessing you made a mistake when you said directory? Since you can't make a custom extension for a directory. A directory is a folder.
    The code i supplied above is for a file, with the custom extension.

  12. #12
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: List a special directory in an OpenFileDialog?

    Quote Originally Posted by Louix
    In my application, I prefer for folders to be self contained because they hold everything todo with the project, I don't like the thought of project folders like Visual Studio makes either.
    I don't quite understand what you mean.

    If you want to save a file you can save it to any location you choose.

    In my OpenFileDialog example i use Environment.SpecialFolder, you can copy that bit of code and modify the last bit, depending on what the directory is.

    Otherwise:

    IO.file.WriteAllText()
    IO.Directory.CreateDirectory()

  13. #13
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: List a special directory in an OpenFileDialog?

    Quote Originally Posted by noahssite
    Also i am guessing you made a mistake when you said directory? Since you can't make a custom extension for a directory. A directory is a folder.
    The code i supplied above is for a file, with the custom extension.
    I don't think so, I think he means folders / directories... I already said above that I didn't think those have extensions so I don't think he's going to be able to do this...

  14. #14
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: List a special directory in an OpenFileDialog?

    Quote Originally Posted by NickThissen
    I don't think so, I think he means folders / directories... I already said above that I didn't think those have extensions so I don't think he's going to be able to do this...
    @NickThissen He has probally made a typo, otherwise how about he enlightens us with what exactly he is doing.

  15. #15

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: List a special directory in an OpenFileDialog?

    I am attempting to make DIRECTORIES/FOLDERS with extensions show up in a OFD. There has to be some way to make Windows think it is a FILE but really it's just a FOLDER??

  17. #17
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: List a special directory in an OpenFileDialog?

    I am not even sure if you can do this with APIs can you? otherwise i am going to pay good attention to this thread, since if you do find an anwser i will be surprised.

  18. #18
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: List a special directory in an OpenFileDialog?

    directories can't have extensions. it might look like an extension, but its just the directory name. you can't filter OFD's for directories

  19. #19
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Re: List a special directory in an OpenFileDialog?

    If you would like to retrieve the directories just use IO.Directory you can retrieve the name, if the name is blahblah.abc then just use .endswith(".abc")

  20. #20
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: List a special directory in an OpenFileDialog?

    Depending on how much you want it to actually look like the real OpenFileDialog (or FolderBrowserDialog), you could write your own control. The actual filtering of the directories then is easy, just look at whatever comes after the "." and only show the directory if that matches with your 'extension'. The rest however will be not that easy...

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: List a special directory in an OpenFileDialog?

    Gah! I have to write my own file browser!!! I know for a fact I couldn't code one that exactly looks like one from the Windows APIs but I could, however, use the listbox control seeing as I did a very very very basic file browser in one before. It's just "will the user adapt to it?" is what I'm worried about.

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: List a special directory in an OpenFileDialog?

    Ok, I've manages to work something out:




    What do you think? It's not complete yet, but it works.

  23. #23
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: List a special directory in an OpenFileDialog?

    And the .luaproj 'things' are folders, not files?

    Why can't you create your own .luaproj extension, which is basically just a textfile listing the files in what are now the .luaproj folders..? That would allow you to filter with .luaproj files and in the end you can do find the files by reading the textfile, instead of using the Directory.GetFiles() method...

    Is there any specific way why you're not doing it that way, or did you not think of it..? I can explain my idea further if you wish if you don't understand it.

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: List a special directory in an OpenFileDialog?

    The thing is, where ever there are .luaproj folders, there'll have to be .luaproj text files. Say that one day, a silly user is cleaning up their computer andthey find these hidden .luaproj text files, they just might think that they're junk files left by my application and just delete them. My application wouldn't be able to find the .luaproj folders, then.

    I'm not using the 'Directory.GetFiles()' method, I'm using 'IO.DirectoryInfo(<path here>) .GetDirectories("*.luaproj")'
    Last edited by Louix; Aug 31st, 2008 at 01:25 PM.

  25. #25
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: List a special directory in an OpenFileDialog?

    I'm not sure what 'luaproj' folders do, but I suppose it stands for LUA Project?
    Then I suppose you are trying to make an application that reads lua files, right?
    Are these folders required, and are they always called "<something>.luaproj"?
    And by required I don't mean required by your application, but by whatever application usually reads the lua files..?

    If the folders are not necessarily called "<something>.luaproj" then I don't see how you could not use my method.

    Let's take the Visual Studio solution (.sln) files for example. They look like fancy visual studio files but in fact they are plain old text files (try opening them with notepad) containing some information visual studio needs to know to open the correct files.

    Now let's take your case as example. Again, I don't know exactly what luaproj folders contain but I'm going to guess that a LUA Project contains .lua files.
    Now in your case you could create your own .luaproj files (if they don't exist already, in that case you could create another extension) which are plain text files (but with a .luaproj extension) containing the paths of every .lua file belonging to that project. These files are NOT hidden (I never said that!), instead, give them a fancy icon and make them the 'core' files your application reads.

    You can then use the .luaproj file just like you use a folder! If all you're doing with the folder is reading the paths of every file inside the folder, then that is exactly the same as storing the paths of every file inside a seperate file, instead of a folder with a special name.

    You could for example have the following layout, just like VisualStudio:

    Code:
    Project directory: <AppName>
        File: <AppName>.luaproj
        Directory: <AppName>
           - File: <LuaFile1>.lua
           - File: <LuaFile2>.lua
           - File: <LuaFile3>.lua
    Then, you make your application open the .luaproj files and read them like textfiles. Inside the .luaproj file you could have something like:
    Code:
    ProjectDirectory = "C:\My Documents\LuaProjects\MyLuaProject"
    ProjectFiles = "C:\My Documents\LuaProjects\MyLuaProject\LuaFile1.lua", "C:\My Documents\LuaProjects\MyLuaProject\LuaFile2.lua", "C:\My Documents\LuaProjects\MyLuaProject\LuaFile3.lua"
    Or something similar...

    You can then parse this text information and you end up with the paths to all the files you need, just like you would if you would open the "C:\My Documents\LuaProjects\MyLuaProject" folder with a FolderBrowserDialog for example.

  26. #26

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: List a special directory in an OpenFileDialog?

    Coming from a mainly Mac environment, I am very used to the "package" concept for documents and projects. Take a Pages document for example: Pages makes it LOOK like a file, but right-clicking on the document displays a menu, plus an option called 'Show Package Contents' which means it's a folder that opens with Pages.

    Digging deeper into the pages folder, on the root level of it, you'll find a tar-ball gzip file called 'index' and you'll also find the contents of the document like images etc etc.

    I am very very used to this concept and I like the 'portability' factor of it.

    My .luaproj folders are copied from a foundation .luaproj file that lies in the same directory of my application executable. Like a Pages document, it holds all kinds of files like Lua source files and other things needed for the external platform that the user's finalised application will run on.

    I don't like messy project folders (and text/XML files describing them) because I find them annoying, I want an all-in-one package to look like a file when it's not. My application doesn't need index files because I'm gonna make it so it knows what it's doing (hopefully!) if not, text/XML files will be used describing the contents of the package.

    I would've used your concept if my application wasn't already tied in a lot with my method. But still, I appreciate your help

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: List a special directory in an OpenFileDialog?

    Nick? Anyone?
    Last edited by Louix; Aug 31st, 2008 at 06:00 PM.

  28. #28
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: List a special directory in an OpenFileDialog?

    I'm not familiar with linux at all that's why I thought your setup was a bit strange. If it is similar on linux however I can understand why you want to do it like this.

    If you don't want to use my method however I think you have no other option that to create your own FolderBrowserDialog.

  29. #29
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: List a special directory in an OpenFileDialog?

    Actually if you want an example of a directory that is in the form of an extension, just take a look at the Call Of Duty .iwd files. It stands for, as far as I know "Internal Working Directory". It's very fun to run an antivirus on the folder and see the internal directory structure of the .iwd as it is scanned.

  30. #30

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: List a special directory in an OpenFileDialog?

    I think .iwd files are some kind of archive files not folders if you have to run them through an AV.

    I don't have a Call of Duty disc but if they are directories, you could open up an NT cmd prompt window and use the "cd" command to see if you can access them as a directory. Please let me know, because of they are folders, I know I'll be able to open them [.luaproj files] in my application and not Windows Explorer.

  31. #31
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: List a special directory in an OpenFileDialog?

    Linux does not operate that way. OSX does because of its Mac heritage of having multiple "forks" to represent a file.

    But, as others have said, it's impossible to run/execute a folder. Windows just does not work that way, and was never intended to, but that's mainly because the file-system setup is the same as it was back when QDOS was just a cheap, stripped-down version of CP/M, and when IBM was still running the PC show. (Of course, DOS, and its derivatives have been vastly upgraded since then, but still retains that file structure setup.)

    Take for example, in Linux/UNIX, a user's folder would be:

    /home/User/ , with a command pointer of ~

    In Windows, it's

    C:\Documents and Settings\User\ with a pointer of %CurrentUser%

    Neither can technically be executed, because they a contain a collection of known address spaces for files. Although a folder can be flagged +X in UNIX, it won't do anything.

    Also, Windows does not support symbolic links like UNIX/Linux does. And with the mass amount of viruses that Windows/DOS has, it's a good thing that it was never implemented.


    Anyhow, I hope that makes sense to you.
    Last edited by Campion; Sep 1st, 2008 at 03:51 PM.

  32. #32
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: List a special directory in an OpenFileDialog?

    I started a response to this design decision in another thread but I think it needs to be mentioned here as well.

    You're trying to re-create functionality that exists in a file browser on a major OS. You're trying to go against standard Windows practices. Why?

    The way I see it you have two choices:
    1. Go the way you're going. Create a customized file dialog that doesn't look like normal ones. This will also make it impossible for users to simply double click on their project to open it into your program. This also makes it impossible to simply add it as an e-mail attachment or upload to a website.

    2. Stick with the Windows way of doing things (you're developing on Windows after all) and create a customized file type. This type of file (.luaproj) would, itself, contain all of the needed files (much like a Zip file). This allows you to use the built in OpenFileDialog. You can allow users to double click onto the file to launch it. You can even upload the entire project to a website (such as VBForums.com) or e-mail it!

    To be honest, rather than trying to work around all these issues; I think you should re-think your design and seriously consider the usability ramifications of your chosen solution.
    Quote Originally Posted by Campion
    Linux does not operate that way. OSX does because of its Mac heritage of having multiple "forks" to represent a file.
    Linux can work that way. The .Application "folder" on OS X is only represented as such in Finder. If you take a look at the actual file system, it's just a regular folder. Also, like a folder, you cannot simply upload a .Application to the web.

    You're right, as far as I know no Window server for Linux works in this way but If someone created their own shell for X they could easily recreate this.
    Quote Originally Posted by Campion
    But, as others have said, it's impossible to run/execute a folder. Windows just does not work that way, and was never intended to, but that's mainly because the file-system setup is the same as it was back when QDOS was just a cheap, stripped-down version of CP/M, and when IBM was still running the PC show. (Of course, DOS, and its derivatives have been vastly upgraded since then, but still retains that file structure setup.)
    Like mentioned before, this "feature" is part of OS X's Finder (there are some utility modifications so you can execute them in Terminal as well). Windows could easily reproduce the same thing if you decided to create your own shell.

    I wouldn't recommend it but it's not related to the file system.
    Quote Originally Posted by Campion
    Also, Windows does not support symbolic links like UNIX/Linux does. And with the mass amount of viruses that Windows/DOS has, it's a good thing that it was never implemented.
    Actually, Vista has symbolic links. It's not quite the same but its there. I believe the SBU (Subsystem for Unix-based Applications) offered by Microsoft may support this.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

Posting Permissions

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



Click Here to Expand Forum to Full Width