NAME

 Win32::FileType - 0.02

This is a tiny module for modifying the file types and extension association. Uses Win32::Registry patch ( http://Jenda.Krynicky.cz/ )!

!!! Be VERY carefull before you try any of the examples. I tried to make them as harmless as posible, but still they may screw up your computer. Generaly spoken, do NOT use this module unless you realy know what are you doing. !!!

Win32::FileType | Non OO functions | Methods and Constructors


Non OO functions

assoc

 assoc($extension, $type_name)
 assoc($extension, $Win32_FileType_object)

Associates an extension with a file type. The second argument may be either a file type name or a Win32::FileType object.

The file type name is NOT the name you see in the explorer under View\Details, but rather the name of the key specifying the file type. That is you have to use assoc('.rtf','Word.RTF') instead of assoc('.rtf','Rich Text Format').

The extension may, but doesn't have to start with a dot.

 Ex.
  use Win32::FileType qw(assoc);
  assoc('.htm','NetscapeMarkup');
  assoc('.html',Win32::FileType::Open('.htm'));

Win32::FileType | Non OO functions | Methods and Constructors

unassoc

 unassoc($extension)

Deletes the association of an extension with a file type.

Connect

 Win32::FileType::Connect($computer_name)
 Win32::FileType::Connect('local')

Connect to a remote registry. All newly created objects will point to the remote machine. Returns 1 if successfull, undef otherwise. The previously created objects remain connected to the machine they were.

You may call this function also as a method, in that case it reconnects only the object and doesn't change the machine new objects will be pointing to.

 Ex.
  use Win32::FileType;
  $txt = Win32::FileType::Open('.txt');
  print "The type of .TXT files on your computer is \"",$txt->Title,"\".\n";

  $server= 'server_name';
  if (Win32::FileType::Connect($server)) {
    $rtxt = Win32::FileType::Open('.txt');
    print "The type of .TXT files on $server is \"",$rtxt->Title,"\".\n";
    $txt->Title($rtxt->Title);
    print "Now they are the same.\n"
  } else {
    print "Cannot connect to ${server}'s registry !\n"
  }

See also Connect_method


Methods and Constructors

Open, Connect_method, Close, Delete, Name, Title

Assoc, Action, DDEAction, DefaultAction, Icon or DefaultIcon, Property, Extensions

ShellEx, Anything

new

 new Win32::FileType( $file_type_name [ , $title ])

Create a new file type. The $file_type_name is the name of key that will contain the file type specification and will be used in ``assoc''. The $title is the text that will be displayed in the Explorer.

If you do not specify the $title, $file_type_name will be used as the title.

If the file type already exists it will be opened. In that case if you do not specify the $title, it will not get changed.

 Ex.
  use Win32::FileType;
  $obj = new Win32::FileType('Perl_module', 'Perl module');
  $obj->Action('open','E:\Soft\PFE\PFE32.EXE "%1"','&Open')

Win32::FileType | Non OO functions | Methods and Constructors

Open

 Win32::FileType::Open( $file_type_name [, $computer)
 Win32::FileType::Open( $extension [, $computer)

Opens a preexisting file type. You may specify either the file type name or an extension (begining with a dot!).

If you specify a computer name, the function tries to connect the remote registry on that computer.

 Ex.
  use Win32::FileType;
  $doc=Win32::FileType::Open('.doc');
  $perl=Win32::FileType::Open('Perl');

Win32::FileType | Non OO functions | Methods and Constructors

Action

 $obj->Action( $action_name, $action [, $title])
 $command = $obj->Action($action_name)
 ($command,$title) = $obj->Action($action_name)

Sets or retrives the command and title of an action of a file type. If you do not specify the title, the name of the action is used instead.

 $action_name = the name of the action, say 'open'
 $title = the text that will be displayed in the local menu for the file type,
          you may use & to specify the hot key, say '&Open'
 $action = the command line that has to be executed for the file type,
           use "%1" to specify where to place the name of the document
           to be opened. say "$ENV{windir}\\notepad.exe \"%1\""

If you use this method to get the info, you may use either the action subkey name or the action title (the text in local menu) or a regular expression matching the action title. If the $action_name is an empty string, you will get info for the default action.

 Ex.
  use Win32::FileType;
  $txt = Win32::FileType::Open('.txt');
  $pm = new Win32::FileType('Perl_module','Perl module');
  $pm->Action('open',$txt->Action('open'));
  $pm->Assoc('.pm');
   #sets the open action for perl modules to the same as opening .txt files

Win32::FileType | Non OO functions | Methods and Constructors

Assoc

 $obj->Assoc($extension)
 $obj->Assoc(@extensions)

Associate the extension(s) with this file type. The extension doesn't have to begin with a dot.

 Ex.
  use Win32::FileType;
  $pm=Win32::FileType::Open('C_source');
  $pm->Assoc('.c','h','cpp','hpp','inc');

Win32::FileType | Non OO functions | Methods and Constructors

Close

 $obj->Close

Closes the Win32::FileType object and releases the handle to registry. It does exactly the same as ``undef $obj;''.

Win32::FileType | Non OO functions | Methods and Constructors

Connect_method

 $remote_obj = $obj->Connect($computer_name)
 $remote_obj = $obj->Connect('local')

Connect to the same file type in on a remote computer. Returns a new Win32::FileType object if successfull, undef otherwise.

This method doesn't change the machine new objects will be pointing to.

 Ex.
  use Win32::FileType;
  $txt = Win32::FileType::Open('.txt');
  print "The type of .TXT files on your computer is \"",$txt->Title,"\".\n";

  $server= 'server_name';
  if ($rtxt=$txt->Connect($server)) {
    print "The type of .TXT files on $server is \"",$rtxt->Title,"\".\n";
    $txt->Title($rtxt->Title);
    print "Now they are the same.\n"
  } else {
    print "Cannot connect to ${server}'s registry !\n"
  }

See also Connect

Win32::FileType | Non OO functions | Methods and Constructors

DDEAction

 $obj->DDEAction( $name ,\%action [, $title])
 $action = DDEAction( $name);
 ($action, $title) = DDEAction( $name);

Sets or retrieves the DDE command and title of an action of a file type. If you do not specify the title, the name of the action is used instead.

If an application supports DDE, it's a very good idea to set up the DDEAction (Shell\action\ddeexec subkey of the file type). This way if you start a document when it's application is already running, the computer doesn't have to launch a new instance of the program, but rather may just tell the existing instance to open a document.

See the docs of the application to see if this is posible, and how should the DDE command look like.

The \%action is a hash (associative array) of form

 (
  '' => the DDE command,
  'Application' => the name of application that should process the command,
  'ifexec' => the executable to run if Application is not runing,
  'topic' => the topic (see the docs of DDE for the application)
 )

 Ex.
  use Win32::FileType;
  $pfe_path='c:\Program files\PFE\PFE32.EXE';
  $txt = Win32::FileType::Open('.txt');
  $txt->Action('open',qq{"$pfe_path" "%1"}, '&Open');
  $txt->DDEAction('open',
   {'' => '[FileOpen("%1")]',
    'Application' => 'PFE32',
    'ifexec' => '"'.$pfe_path.'"',
    'topic' => 'Editor'
   }
  );

Win32::FileType | Non OO functions | Methods and Constructors

Delete

 $obj->Delete
 Win32::FileType::Delete($obj1,$obj2,$obj3,...)

Deletes the file type from the registry (completely). You may delete several types at once.

Returns the number of successfully deleted types.

Win32::FileType | Non OO functions | Methods and Constructors

DefaultAction

 $obj->DefaultAction('Run');
 $action = $obj->DefaultAction();

Retrieves or sets the name of the default action for the file type.

Win32::FileType | Non OO functions | Methods and Constructors

Extensions

 @extensions = $obj->Extensions();
 $obj->Extensions(\@extensions);

Searches for all extensions that are mapped to this file type. May take some time to execute.

If evaluated in array context returns an array of the extensions. If evaluated in scalar context returns the number of extensions found. If the first argument is present it will be set to a reference to an array containing the extensions.

 Ex.
  use Win32::FileType;
  $txt=Win32::FileType::Open('.txt');
  print $txt->Title,' (',$txt->Name,")\n (";
  print join(', ',$txt->Extensions);
  print ")\n";

Win32::FileType | Non OO functions | Methods and Constructors

Icon or DefaultIcon

 $obj->Icon($path_to_the icon)
 $obj->Icon("$path_to_an_EXE,$index")
 $icon = $obj->Icon();

Sets or retrives the default icon for this file type. The path may point either to an .ICO file or to an .EXE or .DLL file. In the later case you should provide an index because an .EXE may contain several icons.

 Ex.
  use Win32::FileType;
  $doc = Win32::FileType::Open('.doc');
  print 'Current icon for ',$doc->Title,' (.DOC) files is ',$doc->Icon,"\n";
  ($exe,$idx) = split(/,/,$doc->Icon());
  $doc->Icon($exe .','. ($idx+1));  # use the next icon in the file
  print 'Current icon for ',$doc->Title,' (.DOC) files is ',$doc->Icon,"\n";

Win32::FileType | Non OO functions | Methods and Constructors

Name

 $obj->Name

Returns the name of the file type. Since I do not know of an easy way to rename a registry key and didn't write a Rename function in Win32::Registry2, this property is read only. I will add Rename and Copy methods later.

Win32::FileType | Non OO functions | Methods and Constructors

Property

 $obj->Property($name,$value)
 $obj->Property($name,$type,$value)
 $value = $obj->Property($name)

Retrieves or sets a value in the main key of the file type. The $type is the registry value type as exported by Win32::Registry2.pm. Default is REG_SZ. If you want to delete a property, specify undef as the value.

 Known properties:
  EditFlags : REG_DWORD : If you know what does that mean, tell me please
  IsShortcut : REG_SZ : Should it be displayed as a shortcut?
   The value is unimportant.
  NeverShowExt : REG_SZ : If the property is present, the explorer will never
   show the extension. The value is unimportant.
  AlwaysShowExt : REG_SZ : Oposit to NeverShowExt.
  Insertable : REG_SZ : ???
  URL Protocol : REG_EZ : ???
  Source Filter : REG_SZ : ???

Win32::FileType | Non OO functions | Methods and Constructors

Title

 $obj->Title($title);
 $title=$obj->Title;

Retrieves or sets the title of the file type.

Win32::FileType | Non OO functions | Methods and Constructors

ShellEx

 $reg=$obj->ShellEx

Gives back a registry object opened to a ShellEx subkey of the file type. See Win32::Registry for available functions. Since it is not so widely used I was too lazy to provide any wrapper over this rarely used area.

Anything

 $obj->Anything($class_id);
 $value = $obj->Anything();

All other functions retrieve or set the default value of the subkey name_of_the_function of the file type key. You may use it to set the CLSID, CurVer and other values.

Win32::FileType | Non OO functions | Methods and Constructors


AUTHOR

Jan Krynicky <Jenda@McCann.cz>


COPYRIGHT

Copyright (c) 1997 Jan Krynicky <Jenda@McCann.cz> All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.