If you look at MyComputer or Windows Explorer, you will notice that if you're in a folder loaded with mp3's or other media files, and you are in Details mode, that you can right-click on the header bar and you will see many more options for columns to display. Great news... Any of this information can be retrieved in PowerBuilder quite simply!
Before I dive into the nuts & bolts of how to retrieve everything, I will start by setting up a simple Custom UserObject called nvo_file. I set it to Auto-Instantiate, and then add an instance variable to hold the path of this object's file, and then a boolean to tell if the object has been set, and yet another private variable to hold a shell object.
[color green]/*nvo_file's instance variables*/
PUBLIC PRIVATEWRITE String is_path, is_folder, is_filename
PUBLIC PRIVATEWRITE Boolean ib_set
PRIVATE OLEObject obj_shell[/color]
Next, we need to initiate the shell object. We will handle this in the Constructor event of nvo_file...
Next, for ease of use, I create a simple UserFunction which returns a Boolean and accepts a String as the sole parm, and call it "is_blank". This function is very useful for simply testing a string to see if it's blank or not... Basically, it's a lazy shortcut to help ward off NULL strings.
[color green]/*is_blank -- returns boolean -- argument: as_test*/
IF IsNull( as_test ) THEN RETURN TRUE
IF as_test = '' THEN RETURN TRUE
RETURN FALSE[/color]
Now, back to nvo_file! I will break each item down into a separate function, rather than using properties. The first function of the UserObject should be one to set the path of the file. I chose to use a function to set the path this way over simply setting the is_path variable so that I only need to call the slow FileExists( is_path ) function once per file. This may not seem like too much of an issue, but many times I loop through thousands of file paths, and the FileExists( ) function is a hog! Also, the way this function is setup, you can tell if the path you passed works or not by what's returned from the set function.
//first off, make sure the path is set to a valid file...
IF ib_set THEN
obj_folder = obj_shell.NameSpace( is_folder ) //folder
obj_item = obj_folder.ParseName( is_filename ) //file
ls_datetime = obj_folder.GetDetailsOf( obj_item, 4 )
//the date can be ripped directly out of the string
ld_date = Date( ls_datetime )
//time cannot be ripped directly out of the string
//a blank space is the separator from the date & time
ls_time = Mid( ls_datetime, Pos( ls_datetime, ' ' ) + 1 )
//combine the two...
ldt_file = DateTime( ld_date, Time( ls_time ) )
END IF
//clear up memory
DESTROY obj_folder
DESTROY obj_item
RETURN ldt_file[/color]
And now you have a functional object that can retrieve the creation date of a file! There are many more properties that you can grab out of a file...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.