473,395 Members | 1,335 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,395 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 27837
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.