Newbie trying to do a file move 
Author Message
 Newbie trying to do a file move

I am trying to learn perl and I dont know how to use modules yet...so
bear with me....

I want to move files from one directory to another that are extensions
.xyz

Can someone post me some code if you have done this already...or else
give me a quick breakdown on how to use a module?

One last thing is that I am building this perl script into an
executeable using Activestate Perl Dev kit.

Thanks in Advance
Nilo



Mon, 10 Jan 2005 19:51:03 GMT  
 Newbie trying to do a file move
Also sprach Nilo:

Quote:
> I am trying to learn perl and I dont know how to use modules yet...so
> bear with me....

Possibly you wont even need modules.

Quote:
> I want to move files from one directory to another that are extensions
> .xyz

Pay particular attention to the glob() function that does shell globbing
for you:


    # or even

It returns all files matching. These are just the bare files, so you
might need to prepend the entries with the path.

As for moving, you can do that with the rename() function. It might not
work across partition boundaries. In such a case have a look at
File::Copy that provies a move() function. So that's the bit about
modules actually.

Quote:
> Can someone post me some code if you have done this already...or else
> give me a quick breakdown on how to use a module?

Here is an easy one:

    my $target_dir = "/target/path";


        rename $file, "$target_dir/$file" or warn $!;
    }

With a module:

    use File::Copy

    my $target_dir = "/target/path/";


        move ($file, $target_dir);
    }

Tassilo
--

pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;



Mon, 10 Jan 2005 20:35:31 GMT  
 Newbie trying to do a file move
On 25 Jul 2002 19:35:31 GMT,

Quote:
> Also sprach Nilo:

>> I am trying to learn perl and I dont know how to use modules yet...so
>> bear with me....

> Possibly you wont even need modules.

>> I want to move files from one directory to another that are extensions
>> .xyz

> Pay particular attention to the glob() function that does shell globbing
> for you:


>     # or even


I, personally, wouldn't recomment this syntax. It's unnecessarily
confusing (looks too much like the readline operation).

Quote:
> It returns all files matching. These are just the bare files, so you
> might need to prepend the entries with the path.

If a list of files is returned, then you can use those file names as
is. What comes back is the expanded list. In the above case, you _are_
in the directory the files are in. If you are not, then you should do
something like:


and each returned file name will be a fully qualified path, and can be
used, again, as is.

If you use opendir(), readdir(), then you need to be aware that you
might need to prepend the path yourself, but glob does not have this
problem.

Martien
--
                        |
Martien Verbruggen      | +++ Out of Cheese Error +++ Reinstall
Trading Post Australia  | Universe and Reboot +++
                        |



Tue, 11 Jan 2005 01:05:14 GMT  
 Newbie trying to do a file move
Also sprach Martien Verbruggen:

Quote:
> On 25 Jul 2002 19:35:31 GMT,


[ glob() ]

Quote:
>> It returns all files matching. These are just the bare files, so you
>> might need to prepend the entries with the path.

> If a list of files is returned, then you can use those file names as
> is. What comes back is the expanded list. In the above case, you _are_
> in the directory the files are in. If you are not, then you should do
> something like:


> and each returned file name will be a fully qualified path, and can be
> used, again, as is.

You are right. I just use globbing so seldom that I indeed confused it
with readdir's behaviour.

Tassilo
--

pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;



Tue, 11 Jan 2005 08:38:16 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. mv, move, or some way to move files in perl

2. mv, move, or some way to move files in perl

3. newbie trying to solve file copying problem

4. Newbie trying to compare two .txt files

5. newbie trying to parse one file into three

6. Perl Newbie trying to parse file

7. html : how replace inner links in a html file when move a file

8. Needed: Script for file tree delete and file tree move

9. Moving from state to state (newbie question)

10. Newbie questions on MOVE

11. Newbie: what the code is doing?

12. Newbie question: load page after script is done

 

 
Powered by phpBB® Forum Software