Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

tree backup script - file type problem

by barathbr (Scribe)
on Sep 07, 2004 at 23:05 UTC ( #389231=perlquestion: print w/replies, xml ) Need Help??

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


I am just in the process of writing a little script to back up specific files from multiple servers on my network. The problem is that some of the files dont have standard extensions. (e.g) I could have a binary with no extension or a cap file named as .txt.

My question is, is there a module which gives output similar to the `file` command ?? I am on windows with A perl 5.8

pl. note I have hunted on cpan for modules, but just wanted to make sure I am using a standar module which people know works

Also, is there a simple way to access windows shares from within a script. I am currently just mapping a drive to the $ share within windows and hardcoding the path. That just increases my login time like crazy.


Replies are listed 'Best First'.
Re: tree backup script - file type problem
by BrowserUk (Patriarch) on Sep 07, 2004 at 23:08 UTC


    use Win32::NetResource; $ShareInfo = { 'path' => "C:\\MyShareDir", 'netname' => "MyShare", 'remark' => "It is good to share", 'passwd' => "", 'current-users' =>0, 'permissions' => 0, 'maxusers' => -1, 'type' => 0, }; Win32::NetResource::NetShareAdd( $ShareInfo,$parm ) or die "unable to add share";

    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
Re: tree backup script - file type problem
by tachyon (Chancellor) on Sep 07, 2004 at 23:36 UTC
Re: tree backup script - file type problem
by davido (Cardinal) on Sep 07, 2004 at 23:44 UTC

    Here's a simple file-type reporter based on File::Type, and of course our wierd friend, File::Find:

    use strict; use warnings; use File::Type; use File::Find; find( sub { -f && print "$_\t => ", File::Type->new()->checktype_filename($_), $/ for $File::Find::name; }, scalar(@ARGV) ? @ARGV : './' );

    It's a little concise; I was trying to have some fun with it. One hint: The 'for' clause is used to alias $_ to $File::Find::name so that I wouldn't have to keep typing it all over the place. Also, since I only use $obj->checktype_filename() once, I chose to not store the object's ref in a variable, but rather, just dereference the return value of File::Type->new(). ...a couple of golf tricks that didn't seem to hurt readability too much.


      Thanks david, I will just try it out with the snippet that you have written here. I think this in tandem with the netresource module should just do the job for me ...
Re: tree backup script - file type problem
by chromatic (Archbishop) on Sep 07, 2004 at 23:35 UTC
Re: tree backup script - file type problem
by ikegami (Patriarch) on Sep 07, 2004 at 23:22 UTC

    The sources for file are available here if you want to try to compile it in Windows.

      Oh no!!! I am not going down that road. I have already seen File::Type on CPAN, but am just concerned about stability issues. This script will be running every once in a while and it just has to be dependable. Thats my only concerns. If it comes to it, I would rather sacrifice time and bandwidth in just mirroring whole directories, since it is on the local network. I was just hoping to get some recomendations on any other modules that people might already be familiar with.

      Thanks anyway

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://389231]
Approved by ikegami
Front-paged by broquaint
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2022-05-29 02:01 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (101 votes). Check out past polls.