Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How get File Properties in Powerbuilder 2

Status
Not open for further replies.

Kongsjs

Programmer
Jul 20, 2007
17
NO
Hi

Is there anyone that know how to get the properties on files in windows from a PB application ?
What I need is the modified Date and Time on files.

I cant find a PB function that give this.
It is probably a Microsoft program I can call to get this, but I have'nt found any and how to do it.

Looking forward to a solution on this :)
 
Personally, I use OLEObjects. I've got a simple Non-Visual User Object that I've called nvo_file... Basically, I parse the file name into that object and have coded all sorts of functionality to it... But the basics of the last mod date/time is:

FUNCTION: uf_file_last_mod( as_filename ) -- returns DateTime

SCRIPT:

String ls_path, ls_file, ls_test
DateTime ldt_ret
OLEObject obj_shell, obj_folder, obj_item

obj_shell = CREATE OLEObject
obj_shell.ConnectToNewObject( 'shell.application' )

ls_path = Left( as_filename, LastPos( as_filename, "\" ) )
ls_file = Mid( as_filename, LastPos( as_filename, "\" ) + 1 )

IF FileExists( as_filename ) THEN
obj_folder = obj_shell.NameSpace( ls_path )

IF IsValid( obj_folder ) THEN
obj_item = obj_folder.ParseName( ls_file )

IF IsValid( obj_item ) THEN
ls_test = obj_folder.GetDetailsOf( obj_item, 3 )
ldt_ret = DateTime( ls_test )
END IF
END IF
END IF

DESTROY obj_shell
DESTROY obj_folder
DESTROY obj_item

RETURN ldt_ret

//hope this helps!
 
Hi

I have tested the solution with OleObjects, and that work perfektly. The function "LastPos" wasnt in PB 7.0, but that was easy to make.

An additional info is that if you change the number (3) to any other number from 0 up to atleast 34 you will get almost every property on files.
--"ls_test = obj_folder.GetDetailsOf( obj_item, 3 )"

I have found this sofar:
0 = "Filename"
1 = "Size"
2 = "Type"
3 = "Modified date"
4 = "Created date"
5 = "Unknown"
6 = "Attributes"
7 = "???"
8 = "Domene"
9 = "Artist"
10= "Tittle"
11= ""
12= "Genre"
13= ""
14= "Comments"
15= ""
16= "Artist"
17= "Album title"
18= "Year"
19= ""
20= "Genre"
21= "Duration"
22= "Bitrate"
23= "Protected"
24= ""
25= ""
26= ""
27= ""
28= ""
29= ""
30= ""
31= ""
32= "???"
33= "Audio sample rate"
34= "Channels"

Thanks a lot for helping me with this !!!
 
Kongsjs,
Correct me if I'm wrong, but I don't think the GetDetailsOf( ) function is limited to 34... I think that it's limited by the file type. But then again, I've been wrong before!
 
Hi
You are right of course. But there wasn’t any values in the fields over 34 on the file types I have tested.
If you or someone else have a more complete list of property fields they would share, so would that be very nice.
 
I wish I did, but seems everyone besides yourself is quite stingy with the file information... They give you the first few, and then it seems you're left to discover the world on your own! This information isn't nearly as readily available as I thought, and I keep burying my cheat sheet on my desk!

A few more notes... The two genres you have listed... One is for the album, the other is for the track. Same with artist and genre... Now, as to which is which, I don't recall off hand, and I don't have any applications here at work that use this. I had a link saved which had the technical definitions of each (for multimedia filetypes, at least), but that was on my old box... I'll see if I can dig it up.
 
Hi,

I like to know if a directory contains any files. In essense, I want to get the size of a directory. I can use PowerBuilder's FileLength or this OLEObject, but I still can't get any information on a directory.

Thanks for any help.
 
Hi citclasspb

I dont know how to get the directory size, but if you need to know if a directory contains files or not, youcan use DIRLIST, and put the result into a listbox, etc.
If you then use function TotalItems to count files in the listbox, you will get what you want.

If you need to know the size, try ask TheklOwn or find all filesizes of the files in the Listbox, and add them together.

Hope this will be of some help.
 
Thanks Kongsjs,

It definitely helped. I only wanted to see if there is a file in the folder. For the directory size, etc., I think I can use f_SetFilesrv.

I used the following to get the total number of *.dat files.

boolean lb_found
integer il_number = 0
lb_found = this.lb_1.DirList("C:\TEMP\DATA\*.dat", 0)
IF lb_found = true THEN //this is a valid directory
il_number = this.lb_1.totalitems()
END IF

Thanks again
 
Don't know if this what version you're using, or if this is of any use to you, or what version this was added (I use 6.5 & 10.5), but in 10.5 there are two functions that help with the file stuff... DirectoryExists( /*TEST_DIR*/ ) and FileExists( /*TEST_FILE*/ ).

I don't remember which way it is, but I believe it's FileExists( ) that will return TRUE for a passed directory. It's a snag that's bit me before!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top