identifying files

Just starting out? Need help? Post your questions and find answers here.
Jacobite
User
User
Posts: 16
Joined: Fri Nov 30, 2012 7:21 pm

identifying files

Post by Jacobite »

I'm writing a program which creates multiple files on the fly which may be deleted, but I need to load all the filenames into a list when the program starts, and also one or more of them will be selected when the program is running. So the question is, how do I identify the files so I can load them when the program starts and later when they might be selected from the list? I can use #PB_Any to create the files but that won't help me to open them because I don't the numbers. Hope this makes sense.

So basically, for each filename, I want to generate a unique number from the filename to use as the filenumber.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: identifying files

Post by Shield »

Why do you have to associate the file name with a number?
OpenFile() used with #PB_ANY gives you a PB file handle which you can use, you don't need to use a number.

I don't really understand what you want to do.
If you know where the file is you can just load it and save the file ID and the path in a custom structure or something
like that to clarify the association.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Jacobite
User
User
Posts: 16
Joined: Fri Nov 30, 2012 7:21 pm

Re: identifying files

Post by Jacobite »

Maybe I'm misunderstanding something, but doesn't each file need to have a unique number in order to open it? I suppose my program works a bit like a database, only instead of Tables I'm using files. I want to be able to select any file (from a list) to be loaded at any time during the program, but these files can also be deleted.

Edit: Ok, I was confused. :lol:

Problem solved.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: identifying files

Post by Shield »

Yes, that's what #PB_ANY is for. It gives you a unique "handle" every time you open a file.
The whole stuff about IDs is a PB thing. It's not really used anywhere else, at least I never saw it before and after my PB time.

WinAPI for example always gives you a handle, i.e. it always behaves similar like #PB_Any.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: identifying files

Post by Fred »

It's more like a BASIC thing. FreeBasic for example has it as well: http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgOpen

Be sure to read this: http://www.purebasic.com/documentation/ ... jects.html
Post Reply