|
-
Aug 21st, 2008, 12:19 PM
#1
Thread Starter
Addicted Member
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.
-
Aug 21st, 2008, 12:46 PM
#2
Re: List a special directory in an OpenFileDialog?
vb Code:
Dim ofd As New OpenFileDialog()
ofd.Filter = "Description here (*.luaproj)|*.luaproj"
if ofd.showdialog 'etc
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 24th, 2008, 12:27 PM
#3
Thread Starter
Addicted Member
Re: List a special directory in an OpenFileDialog?
Doesn't work
-
Aug 24th, 2008, 12:37 PM
#4
Fanatic Member
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
-
Aug 24th, 2008, 02:05 PM
#5
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.
-
Aug 24th, 2008, 03:20 PM
#6
Fanatic Member
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.
-
Aug 25th, 2008, 07:59 AM
#7
Re: List a special directory in an OpenFileDialog?
 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?
-
Aug 29th, 2008, 04:27 PM
#8
Thread Starter
Addicted Member
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.
-
Aug 29th, 2008, 04:38 PM
#9
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.
-
Aug 29th, 2008, 05:12 PM
#10
Thread Starter
Addicted Member
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.
-
Aug 29th, 2008, 05:20 PM
#11
Frenzied Member
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'on the click event of Button 1 *You must first add button 1 if you were to use this exact code* :
Dim mydialog As New OpenFileDialog
With mydialog
.Title = "Open Dialog"
.InitialDirectory = (Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
.Filter = "luaproj files|*.luaproj"
If .ShowDialog = Windows.Forms.DialogResult.OK Then
'Here you can do what you want once the users selects a file,
'to reference the selected files path use .filename
'Here is an example of what you can do. I will display the text in
'the .luaproj file, in a messagebox.
MsgBox(IO.File.ReadAllText(.FileName))
End If
End With
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.
-
Aug 29th, 2008, 05:24 PM
#12
Frenzied Member
Re: List a special directory in an OpenFileDialog?
 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()
-
Aug 29th, 2008, 05:28 PM
#13
Re: List a special directory in an OpenFileDialog?
 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...
-
Aug 29th, 2008, 05:35 PM
#14
Frenzied Member
Re: List a special directory in an OpenFileDialog?
 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.
-
Aug 29th, 2008, 05:40 PM
#15
Re: List a special directory in an OpenFileDialog?
 Originally Posted by Louix
I need to show a directory/folder that has the extension .luaproj, not files with .luaproj.
Don't think that is a typo...??
-
Aug 29th, 2008, 05:41 PM
#16
Thread Starter
Addicted Member
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??
-
Aug 29th, 2008, 05:43 PM
#17
Frenzied Member
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.
-
Aug 29th, 2008, 06:32 PM
#18
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 29th, 2008, 06:41 PM
#19
Frenzied Member
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")
-
Aug 30th, 2008, 04:00 AM
#20
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...
-
Aug 30th, 2008, 08:55 AM
#21
Thread Starter
Addicted Member
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.
-
Aug 31st, 2008, 12:57 PM
#22
Thread Starter
Addicted Member
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.
-
Aug 31st, 2008, 01:02 PM
#23
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.
-
Aug 31st, 2008, 01:13 PM
#24
Thread Starter
Addicted Member
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.
-
Aug 31st, 2008, 01:30 PM
#25
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.
-
Aug 31st, 2008, 04:16 PM
#26
Thread Starter
Addicted Member
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
-
Aug 31st, 2008, 05:53 PM
#27
Thread Starter
Addicted Member
Re: List a special directory in an OpenFileDialog?
Last edited by Louix; Aug 31st, 2008 at 06:00 PM.
-
Sep 1st, 2008, 10:39 AM
#28
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.
-
Sep 1st, 2008, 10:44 AM
#29
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.
-
Sep 1st, 2008, 02:13 PM
#30
Thread Starter
Addicted Member
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.
-
Sep 1st, 2008, 03:48 PM
#31
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.
-
Sep 2nd, 2008, 09:46 AM
#32
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.
 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.
 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.
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|