INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Media

How to read file information using FolderObjects & FolderItem's by thekl0wn
Posted: 6 Jun 08

Reading File Properties in PowerBuilder

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.

/*nvo_file's instance variables*/
PUBLIC PRIVATEWRITE String is_path, is_folder, is_filename
PUBLIC PRIVATEWRITE Boolean ib_set
PRIVATE OLEObject obj_shell


Next, we need to initiate the shell object.  We will handle this in the Constructor event of nvo_file...

/*nvo_file constructor event*/
obj_shell = CREATE OLEObject
obj_shell.ConnectToNewObject( 'shell.application' )


And likewise in the destructor event, I like to manually clear up my memory...

/*nvo_file destructor event*/
DESTROY obj_shell


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.

/*is_blank -- returns boolean -- argument: as_test*/
IF IsNull( as_test ) THEN RETURN TRUE
IF as_test = '' THEN RETURN TRUE

RETURN FALSE


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.

/*nvo_file.of_set_file( String as_path ) returns Boolean*/
IF FileExists( as_path ) THEN
  is_path = as_path
  is_folder = Left( is_path, LastPos( is_path, '\' ) )
  is_filename = Mid( is_path, LastPos( is_path, '\' ) + 1 )
  ib_set = TRUE
ELSE
  is_path = ''
  is_folder = ''
  is_filename = ''
  ib_set = FALSE
END IF

RETURN ib_set


Now that we have everything set up to set our file, let's do a function to get the creation date of the file...

/*nvo_file.of_get_creation_date( ) returns DateTime*/
String ls_datetime, ls_time
DateTime ldt_file
Date ld_date
OLEObject obj_folder, obj_item

//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


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...

Back to Sybase: PowerBuilder FAQ Index
Back to Sybase: PowerBuilder Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close