Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Perl & Window's system stuff: Can they get along?

by akm2 (Scribe)
on Mar 19, 2001 at 02:58 UTC ( [id://65314]=perlquestion: print w/replies, xml ) Need Help??

akm2 has asked for the wisdom of the Perl Monks concerning the following question:

I have recently started setting up an E-System. The Website is now ODBC controled. SSL is up and running. The client side apps are allmost ready. However I neded some help. The client side apps will be distributed world wide. So I need An install program. For this I have 3 questions.

1. How can I make Perl except long file/directory names?
Example: If (!-e C:\\My Long Directory Name\\My Long File Name.ext){ print "File not exist!\n"; }

2. How Do I create a windows link (a .lnk file) using perl?

3. How do I find out the name/location of Windows system stuff?
Example the Windows Directory is not the norm of C:\windows. Instead the Windows Directory is D:\WinSysFiles. Or, lets say I need to get the path to use If I want to add a link to the Start Menu.

Can perll to these functions? If so, how? Any help would be GREAT! :)

Replies are listed 'Best First'.
Re: Perl & Window's system stuff: Can they get along?
by orbital (Scribe) on Mar 19, 2001 at 04:26 UTC
    To open long filenames with spaces enbedded use single quotes.

    To make a shortcut use Win32::Shortcut, it comes standard with the ActiveState distrubution.

    To find out the system path I probably wouldn't do it through perl I would probably use a system call to the Dos shell and use the Enviromental Variables there it would be much easier to access. Otherwise the only way I can think of off hand is to use Win32::TieRegistry or Win32::Registry.

    great sources of Win32 info is http://perl.dada.it or David Roth's Site Roth has written many Win32 modules and has several very good book on the subject on programming and administrating a Win32 environment. Be careful his books aren't intended for the novice they assume a solid understanding of perl's core functions.

      On an NT-based system, there's no need to do a system call to the shell to determine the Windows directory. $ENV{windir} (or $ENV{SystemRoot}) has it.

      Update: As pointed out below, $ENV{windir} works on 9x systems as well.

        $ENV{'windir'} also works fine on 9x.
        In 9x the start menu can be found in the registry :
        'HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Start Menu'
        I dont know about NT/2k, but it should be the same. hope this helps you
        Braindead One
(crazyinsomniac: so lazy, what a shame) Re: Perl & Window's system stuff: Can they get along?
by crazyinsomniac (Prior) on Mar 19, 2001 at 12:51 UTC
    I'm suprised you did not look at your perl documentation, look what I found just in the table of contents. All of the following come with the standard perl distribution: (at least ActivePerl and Indigoperl)
    perl5004delta perlamiga perlcygwin perldos perlhpux perlmachten perlos2 perlos390 perlvms perlwin32 <<<<< See that, that's part of the standard documentat +ion Win32 <<<<< just like perldata, perlop, perlsyn, perlre ... use Win32; Win32::CopyFile(FROM, TO, OVERWRITE) Win32::CopyFile() Win32::GetFullPathName(FILENAME) Win32::GetShortPathName() Win32::GetLongPathName() Win32::Spawn(COMMAND, ARGS, PID) File::Spec::Win32 Win32::File; Win32 API AuthenticateUser ChangeNotify Clipboard Console DBIODBC DDE Callback Client Event EventLog File FileSecurity Internet IPC Mutex NetAdmin NetResource ODBC OLE Browser Browser Const Enum NEWS NLS TPJ Variant PerfLib Pipe Process Registry Semaphore Service Sound TieRegistry Win32API File Net Registry

     
    ___crazyinsomniac_______________________________________
    Disclaimer: Don't blame. It came from inside the void

    perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Re: Perl & Window's system stuff: Can they get along?
by Corion (Patriarch) on Mar 19, 2001 at 03:50 UTC

    I suggest you have a close look at how the IndigoPerl installer does the installation / setup of IndigoPerl. They create links to Apache in the Start Menu.

    For the name and location of the special system folders, you could either dig in the registry for the keys that hold these values (Win32::TieRegistry would be a good module) or you could use the appropriate Win32 system calls (Win32::API is the module for that).

Re: Perl & Window's system stuff: Can they get along?
by damian1301 (Curate) on Mar 19, 2001 at 03:14 UTC
    1. unless(-e 'C:/Bah/bah/black/sheep'){print "doesn't exist";}
    2.you open it. This will automatically create it.
    3. File::find might work for this, I am not too sure though.

    Almost a Perl hacker.
    Dave AKA damian

    I encourage you to email me
Re: Perl & Window's system stuff: Can they get along?
by clemburg (Curate) on Mar 19, 2001 at 15:28 UTC

    Also, to get filename handling with DOS-like wildcards under Win32 right, you will need to use File::DosGlob in your scripts.

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

Re: Perl & Window's system stuff: Can they get along?
by thabenksta (Pilgrim) on Mar 19, 2001 at 20:07 UTC
    As far as the filename, in dos you can use the first six letters(w\o spaces) a '~' and a sequential number. Ex. C:\Program Files\ would be C:\progra~1, and C:\Programming would be C:\progra~2. Hope this helped. thaben~1

      This is fairly dangerous advice. If you have two files / directories with long names, say "directory_A" and "directory_B", they don't get the same short name, "direct~1", but they get "direct~1" and "direct~2" on a first-come, first-served base.

      If, under Windows NT (SP3 and higher I believe), the number of long filenames gets larger than 100, NT ditches the serial assignment of short filenames due to performance reasons (always looking at all filenames to get the next number takes too long) and uses a hash of the long filename to create the short name and moves on if collisions were found. Thus, under NT, it's quite possible to see filenames such as "dir~DEAD" as the short name for any of the two long names.

      Also, if prior to the installation of Windows on a harddisk already formatted with the FAT32 filesystem, there already exists a directory with the name "Programming" (or, as with the german installation of Windows, where the directory "Program Files" has been correctly translated into "Programme") without "Program Files" having been there before, "Program Files" will have the short name "Progra~2". I can also tell you that hardcoding "C:/Program Files" into your programs will only bring you aggravated international users, as the name "Program Files" is not universal over the various language versions of Windows.

        ok,ok. not a good idea. so sorry. (jk)
      You also forgot that directories with dots in their names like 'c:\stu.shi\' turn into 'c:\stu~1.shi\' so just use Win32;

       
      ___crazyinsomniac_______________________________________
      Disclaimer: Don't blame. It came from inside the void

      perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://65314]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found