473,372 Members | 1,059 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,372 software developers and data experts.

How to copy files from one directory to another?

Hello every one,

my question is how to copy from one directory to another directory (Windows)?

clearly:

c:\perl> present working directory

I have to copy all the text files(*.txt), lets take 5 files from d:\textfile\ directory to e:\copied\ directory.

note: all are different directories.

please help me asap

Thanks in advance
Prasad
Nov 17 '08 #1
7 27834
Try this
File::Copy
Nov 17 '08 #2
Try this
File::Copy
Thanks for the replay its not working..

error: file cant be find.

files are there even though iam getting

copy command iam using
copy ("C:/prasad/SONGS/songs/movie_list/*.txt",, "C:/prasad/SONGS/temp/radio/create/");
Nov 17 '08 #3
Thanks for the replay its not working..

error: file cant be find.

files are there even though iam getting

copy command iam using
copy ("C:/prasad/SONGS/songs/movie_list/*.txt",, "C:/prasad/SONGS/temp/radio/create/");

If you want to copy multiple file use File::Glob to get all the files. After that do a foreach on that arry to copy all files one by one.

otherwise you can simply use copy command in backticks (`) or within system command.
Nov 17 '08 #4
ahgan
13
If you do not want to use additional library, you can use the conventional opendir/readdir functions to read in all the files into array, then use the foreach loop and system command to copy the file into the destination folder.

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. my $pwd = "C:\\perl";
  5. my $destination = "D:\\textfile";
  6.  
  7. opendir(DIR,"$pwd") or die "Cannot open $pwd\n";
  8. my @files = readdir(DIR);
  9. closedir(DIR);
  10.  
  11. foreach my $file (@files) {
  12.     next if ($file !~ /\.txt$/i);  # filtered only file with extension .txt
  13.     system("copy \"$pwd\\$file\" \"$destination\""); 
  14. }
The additional (\") in the system command is to make sure the command line takes in the space as part of the directory path name.
Nov 18 '08 #5
KevinADC
4,059 Expert 2GB
Please do not provide code to people that show no effort to first solve their own coding problems, especially simple ones like this.
Nov 18 '08 #6
ahgan
13
Oops... my bad. Will take note of that.
Nov 19 '08 #7
if you want copy one directory which contain many subfolders and files and other types then this command is used
xcopy d:\mainfiles c:\rinku /e /i /h
Nov 4 '10 #8

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

Similar topics

11
by: Mike | last post by:
I want to be able to copy a directory of files (all .HTM files) from a network drive to a local drive on the machine c:\HTMFiles , How can i do that? I tried File.Copy(source, dest) but i need...
1
by: Green | last post by:
Hi, I had a question about how to copy files from server to server on the same LAN. Basically, i need to copy files from "develope server" to the "test server", then eventually to the "production...
8
by: Chris Strobel | last post by:
I have 2 web servers where I need to write a PDF file and need to keep them in sync. In others words, If the Server1 is getting called to create the PDF, then it needs to copy the PDF to the other...
0
by: Don | last post by:
I intermittently get a runtime Compilation Error that says 'The compiler failed with error code 2000'. It appears that a DLL cannot be found in the 'temporary asp.net files' directory. The...
14
by: **--> That Guy Downstairs | last post by:
What files are needed to be #included to be able to copy files to a new directory and be portable? ie. use it in Unix (SGI and Linux) or Windows 2000. #ifdefs Ok. using dirent.h on SGI, but...
11
by: MarkusR | last post by:
Good day, I need to safely copy files from one directory to another. I need to make sure that I do not lock the file making it unreadable by others. I am not sure if this is the default...
2
by: Paul | last post by:
I need to copy files from an ftp directory to a web-accessible directory and then delete the files in the ftp directory. (I am doing it this way because web-based form upload can not exceed 2MB...
1
by: dkmarni | last post by:
Hi, I am trying to do this perl script, but not able to complete it successfully. Here is the description what the script has to do.. Accept two and only two command line arguments. Again,...
2
by: xoinki | last post by:
hi all, I want to copy contents of one directory to another directory in VC++ using win32 library.. although copy file is there.. I cannot use it since I do not know the filenames.. so I want to...
2
by: parmarjm | last post by:
Hi I am trying to copy files from mapped drive (J:\) to a different machine. The perl script is going to run on my machine to copy files from one place to another. File transfer works when i copy...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.