Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Copy from the curent directory to...

by freak
on Dec 29, 2003 at 21:32 UTC ( #317560=perlquestion: print w/replies, xml ) Need Help??

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

I'm kind of conused, or maybe i just don't use the correct commands, but i cant make a script that will copy a spesific file let's say blabla.jpg from the current folder, to a specific folder - let's say c:\games Can somebody PLEASE give me the script that will do it :)

Replies are listed 'Best First'.
Re: Copy from the curent directory to...
by talexb (Canon) on Dec 29, 2003 at 21:43 UTC

    You can either just issue the appropriate system command like (assuming you're on Win32 by the backslash in your path) copy blabla.jpg c:\games from within your script, or you could use the CPAN module File::Copy which takes care of all of the OS specific separators for you.

    Sorry, I won't write the script for you .. try a few things and see what works.

    --t. alex
    Life is short: get busy!
Re: Copy from the curent directory to...
by tachyon (Chancellor) on Dec 30, 2003 at 00:24 UTC

    You are kidding right? Try this (you type it at the command prompt - Start|Run|cmd.exe):

    C:\>copy /? Copies one or more files to another location. COPY [/V] [/N] [/Y | /-Y] [/Z] [/A | /B ] source [/A | /B] [+ source [/A | /B] [+ ...]] [destination [/A | /B]] source Specifies the file or files to be copied. /A Indicates an ASCII text file. /B Indicates a binary file. destination Specifies the directory and/or filename for the new fil +e(s). /V Verifies that new files are written correctly. /N Uses short filename, if available, when copying a file +with a non-8dot3 name. /Y Suppresses prompting to confirm you want to overwrite a +n existing destination file. /-Y Causes prompting to confirm you want to overwrite an existing destination file. /Z Copies networked files in restartable mode. The switch /Y may be preset in the COPYCMD environment variable. This may be overridden with /-Y on the command line. Default is to prompt on overwrites unless COPY command is being executed from within a batch script. To append files, specify a single file for destination, but multiple f +iles for source (using wildcards or file1+file2+file3 format). C:\>

    So to do it just type (say this) at the command prompt:

    copy blabla.jpg c:\games copy .\*.jpg c:\all_jpegs

    The DOT dir is the current dir and * is a wildcard that matches anything so .\*.jpg means match anything in the current directory that ends in .jpg. You can call shell from perl like this using backtics

    #!/usr/bin/perl `copy blabla.jpg c:\\games`;

    NOTE you need 2 backslashes everyhwere you want a single backslash because of the special nature of the \ char in strings ie \n is a newline and \\ is a literal backslash.

    You can also use the File::Copy module which has the advantage of working across operating systems although somehow I don't see that as a likely issue for you.

    #!/usr/bin/perl use File::Copy; copy( 'file1', 'file2' );
    <code>

    cheers

    tachyon

Re: Copy from the curent directory to...
by iburrell (Chaplain) on Dec 30, 2003 at 01:40 UTC
    If you want to write portable Perl, then you should use the File::Copy module to do the job.
    use File::Copy; copy('blabla.jpg', 'c:\games');
Re: Copy from the curent directory to...
by Hagbone (Monk) on Dec 29, 2003 at 23:56 UTC
    >or maybe i just don't use the correct commands, but i cant make a script that will copy a spesific file let's say blabla.jpg from the current folder, to a specific folder

    Including the code you've (unsucessfully) tried is really important if you'd like some help. Copying files is pretty basic stuff, and if you're having problems with copying, it may mean that there are other issues causing the problem.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2021-01-26 00:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?