473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

copying files

Hi All,
I want to copy some files from one dir in d:, to another dir in c:, i tried using xcopy but it says too many parameters!!pls give suggestions

another thing i wanted to know is how can i invoke command prompt from perl??
Jul 31 '07 #1
13 7572
numberwhun
3,509 Expert Mod 2GB
Ok, first, when you post a question, it is always recommended that you post the code that you have tried thus far so we can help you tweak it and learn. That said, what have you tried?

I am not versed in xcopy, but you could always check out the module called File::Copy, which will enable you to copy files. If it is directories that you are looking to move and not just files, then you will want to read up on File::Copy::Recursive.

For anything you want to do, just search CPAN and see what is available.

As for your "invoking the command line" question, I am not exactly sure what you are asking. If it is as simple as wanting to run a system level command from a Perl script, then just enclose the command and its options in back ticks:

Expand|Select|Wrap|Line Numbers
  1.    `ps -ef | grep <process>`
  2.  
If you are refering to obtaining user input, then you will want to do some reading of the perldoc perlsyn page as it contains examples of the use of the <STDIN> filehandle.

If that is not what you are looking for, then you will need to please rephrase your question and let us know exactly what you are looking for and looking to do.

Regards,

Jeff Kirkland
Jul 31 '07 #2
KevinADC
4,059 Expert 2GB
if on windows:

c:\>xcopy /?



Expand|Select|Wrap|Line Numbers
  1. Copies files and directory trees.
  2.  
  3. XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/W]
  4.                            [/C] [/i] [/Q] [/F] [/L] [/H] [/R] [/T] [/u]
  5.                            [/K] [/N]
  6.  
  7.  source       Specifies the file(s) to copy.
  8.  destination  Specifies the location and/or name of new files.
  9.  /A           Copies files with the archive attribute set,
  10.               doesn't change the attribute.
  11.  /M           Copies files with the archive attribute set,
  12.               turns off the archive attribute.
  13.  /D:date      Copies files changed on or after the specified date.
  14.               If no date is given, copies only those files whose
  15.               source time is newer than the destination time.
  16.  /P           Prompts you before creating each destination file.
  17.  /S           Copies directories and subdirectories except empty ones.
  18.  /E           Copies directories and subdirectories, including empty ones.
  19.               Same as /S /E. May be used to modify /T.
  20.  /W           Prompts you to press a key before copying.
  21.  /C           Continues copying even if errors occur.
  22.  /I           If destination does not exist and copying more than one file,
  23.               assumes that destination must be a directory.
  24.  /Q           Does not display file names while copying.
  25.  /F           Displays full source and destination file names while copying.
  26.  /L           Displays files that would be copied.
  27.  /H           Copies hidden and system files also.
  28.  /R           Overwrites read-only files.
  29.  /T           Creates directory structure, but does not copy files. Does not
  30.               include empty directories or subdirectories. /T /E includes
  31.               empty directories and subdirectories.
  32.  /U           Updates the files that already exist in destination.
  33.  /K           Copies attributes. Normal Xcopy will reset read-only attributes.
  34.  /Y           Overwrites existing files without prompting.
  35.  /-Y          Prompts you before overwriting existing files.
  36.  /N           Copy using the generated short names.
may vary from one version of windows to another
Jul 31 '07 #3
Hi,
following piece of code i tried,and used file::copy module which u had suggested

Expand|Select|Wrap|Line Numbers
  1. Fn_Copy("D:\\SticUtils", "$path",
  2.     qw(SticConf.exe,sticpref.exe,sticdump.exe,sticclient.exe)
  3. );
  4.  
  5. sub Fn_Copy {
  6.     my $Sourc = $_[0];
  7.     my $Destination = $_[1];
  8.     @_ = ($_[2],$_[3],$_[4],$_[5]);
  9.  
  10.     foreach ( @_) {
  11.         print $Sourc."\\".$_;
  12.         print "\n";
  13.         print $Destination."\\".$_;
  14.         copy($Sourc."\\".$_, $Destination."\\".$_);
  15.     }
  16. }
  17.  
the code works fine if there is only one element in array...if i add more than one element it doesnot works.

i want to invoke command prompt on windows and execute some task on the same, how can i invoke the command prompt using perl script??
Aug 1 '07 #4
KevinADC
4,059 Expert 2GB
do you see what the problem is by doing this:

Expand|Select|Wrap|Line Numbers
  1. Fn_Copy ("D:\\SticUtils", "$path", qw(SticConf.exe,sticpref.exe,sticdump.exe,sticclient.exe));
  2.  
  3.  
  4. sub Fn_Copy {
  5.    my $Sourc = $_[0];
  6.    my $Destination = $_[1];
  7. #   @_ = ($_[2],$_[3],$_[4],$_[5]);
  8.    print $_[2];
  9. }
look at what gets printed, it's not "SticConf.exe".
Aug 1 '07 #5
true it prints all the data as $_[2]..any idea how can i fix it!!
Aug 1 '07 #6
KevinADC
4,059 Expert 2GB
one way to send and recieve arguments to a function:

Expand|Select|Wrap|Line Numbers
  1. Fn_Copy ('D:/SticUtils', $path, 'SticConf.exe', 'sticpref.exe','sticdump.exe', 'sticclie nt.exe');
  2.  
  3.  
  4. sub Fn_Copy {
  5.    my $Sourc = $_[0];
  6.    my $Destination = $_[1];
  7.    my @Files = @_[2..5];
  8.    foreach my $files (@Files) {
  9.       do something with $files
  10.    }
  11. }
the above is a "non destructive" way: the contents of @_ are not changed.

A "destructive" way is:

Expand|Select|Wrap|Line Numbers
  1. Fn_Copy ('D:/SticUtils', $path, 'SticConf.exe', 'sticpref.exe','sticdump.exe', 'sticclie nt.exe');
  2.  
  3.  
  4. sub Fn_Copy {
  5.    my $Sourc = shift;
  6.    my $Destination = shift;
  7.    my @Files = @_;
  8.    foreach my $files (@Files) {
  9.       do something with $files
  10.    }
  11. }
the contents of @_ are changed but it really does not matter in this context.

Note: you can use forward slashes with windows in directory paths. You should also almost never put double-quotes around a single scalar variable like you did with $path. It is inefficient and can hide problems that even "strict" and "warnings" may not be able to help you find and fix. Use double-quotes to construct strings that need variable or meta character interpolation and single-quotes to construct strings that do not need variable or meta character interpolation.

$bar = 'bar'; # good
$foo = 'foo'; # good
$foo = "foo"; # bad but works
$foo = "foo\n"; # good because \n is a meta character
$foo = "$bar"; # bad but works
$foo = $bar; # good
$foo ="$bar $blah"; # good because you had to make a new string
$foo = $bar . $blah; # the same as above using concatenation
Aug 1 '07 #7
thanks very much it works fine now.

Do you have any idea how could i access command prompt using perl script,do i need to use any module?

I want to execute some commands from command prompt.
Aug 1 '07 #8
KevinADC
4,059 Expert 2GB
to run a perl program from the command prompt, you can often do it like this:

c:\>perl scriptname.pl

if perl is not in the command path you have to use the fully qualified path to perl:

c:\>perl\bin\perl.exe scriptname.pl

or change directory to the c:\perl\bin folder first then type:

perl scriptname.pl
Aug 1 '07 #9
you answered my question other way, i want to invoke command prompt using a perl script and then execute some commands on it.
Aug 1 '07 #10
KevinADC
4,059 Expert 2GB
you answered my question other way, i want to invoke command prompt using a perl script and then execute some commands on it.
You don't really invoke the command prompt from perl. If you want to run a perl program as a terminal script you start it the way I showed you and prompt for user input. A simple example:

Expand|Select|Wrap|Line Numbers
  1. print "Enter some data:"
  2. chomp(my $input = <STDIN>);
  3. print $input;
  4.  
Is this what you mean?
Aug 1 '07 #11
kevin:
let me give you an example program

You have been asked to write a program which ask you to run some exe files from the command prompt.

I belive following steps should be followed:
1)Invoke the command prompt.
2)move to the dir where you have kept your exe file.
3)execute the exe.

I hope you understand what exactly i am looking at.
Aug 1 '07 #12
KevinADC
4,059 Expert 2GB
kevin:
let me give you an example program

You have been asked to write a program which ask you to run some exe files from the command prompt.

I belive following steps should be followed:
1)Invoke the command prompt.
2)move to the dir where you have kept your exe file.
3)execute the exe.

I hope you understand what exactly i am looking at.
I understand, you do not understand. Either you invoke the command prompt yourself, not your perl script, and enter:

c:\>perl yourscript.pl[list of arguments]

or you run your sript as a terminal based script that prompts for user input. As far as running external applications (exe files for example) you can use;

system()
qx// (same as backtiks)
exec() (but this exits your current perl program)

You can look up all the above on the perldoc website:

http://perldoc.perl.org/

another helpful link:

http://www.perl.org/books/beginning-perl/

This is as much help as I can give you at this point. If you write some code I can help you with your code.

-Kevin
Aug 1 '07 #13
numberwhun
3,509 Expert Mod 2GB
kevin:
let me give you an example program

You have been asked to write a program which ask you to run some exe files from the command prompt.

I belive following steps should be followed:
1)Invoke the command prompt.
2)move to the dir where you have kept your exe file.
3)execute the exe.

I hope you understand what exactly i am looking at.
I completely agree with Kevin that you don't understand. Step #1 should be removed from your list. You do not invoke a command prompt from a Perl script. Like he said, you can run programs from within your Perl script, either by using system() or enclosing the command call in back tics. That said, you can simply remove step #2 from your list as well because you can simply call your file using its full path.

Also, why does this sound distinctly like a homework assignment? I highly recommend "Learning Perl, 4th Edition " for your reading pleasure.

Regards,

Jeff
Aug 1 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Alex Vinokur | last post by:
Copying files : input to output =============================== C/C++ Performance Tests ======================= Using C/C++ Program Perfometer http://sourceforge.net/projects/cpp-perfometer...
1
by: Sarah | last post by:
Hi, Can someone please tell me if there's a way to copy image files from one server to another using ASP and FSO? Or perhaps some other way to do it? I'm trying to collect information on...
11
by: KK | last post by:
Hello, I am running into a problem for copying files between 2 different servers. I am using the following lines of code to do that, but I get a 'permission denied' error Set fso =...
10
by: Alex Vinokur | last post by:
ofstream outfile ("out"); ifstream infile ("in"); istream_iterator<char> iter(infile), eos; Is it possible to copy 'infile' to 'outfile' using 'iter' and 'eos'? -- Alex Vinokur...
3
by: Peter van der Veen | last post by:
Hi IN VB6 there was a control which you can use to show a small avi when for instance copying files (tyhe flying papers). How can one do that in VB.NET??? Peter
8
by: utab | last post by:
Hi there, I am copying one file into another file character by character. I wanted to learn if there is a faster way of doing this? When files get bigger, maybe this can take a lot of time....
0
by: mlfblom | last post by:
Hi, I am running visual studio 2005 on a Vista Ultimate client. I have created a remote site on a Windows 2003 R2 server. This site has about 100 aspx, many App_Code files and several references...
2
by: hello123hello | last post by:
I want to run lime wire but it won't let me install it. It always stops at the copying files spot. I use mozilla firefox and i was wondering how do you get Java Runtime Environment to install?
11
Ali Rizwan
by: Ali Rizwan | last post by:
Hello everybody. I have a problem in fso.copyfiles in vb6.0.Please help me in copying files and how to rename them. Thanks
6
by: kimiraikkonen | last post by:
Hi, I use system.io.file class to copy files but i have a difficulty about implementing a basic / XP-like progress bar indicator during copying process. My code is this with no progress bar,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.