473,395 Members | 1,377 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.

Copying sub directories

Hi,
I would like to know how to copy certain types of files from a group of directories into another group of directories.
Jul 1 '08 #1
3 1126
eWish
971 Expert 512MB
What have you tried? In the meantime look into mkdir, readir, File Find and File::Copy to get you started.

--Kevin
Jul 1 '08 #2
Hi,
i am trying to copy 1 set of files to a folder from an existing directory tree.
Can you please tell me what is wrong with this code?

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use File::Copy;
  4. use File::Glob;
  5.  
  6. my $Src_Dir = 'C:\Documents and Settings\abcd';
  7. my $Dest_Dir_Gel = 'C:\gel';
  8. my $Dest_Dir_Res = 'C:\Results';
  9.  
  10. Sub dir_read
  11. {
  12.  # parse directory and sub directories for files
  13.  
  14.  # Declarations
  15.  my @Dir_List;
  16.  my @Gel_List;
  17.  my @Res_List;
  18.  my $Dir_Name = $_[0];
  19.  
  20.  # Create directories with module name 
  21.  mkdir "$Dest_Dir_Gel\$Dir_Name";
  22.  mkdir "$Dest_Dir_Res\$Dir_Name";
  23.  
  24.  foreach (@Dir_List){
  25.  
  26.   opendir(cDIR, $Dir_Name);
  27.  
  28.   # List the .gel and .res files 
  29.   @Gel_List = <*.gel>;
  30.   @Res_List = <*.res>;
  31.  
  32.   #copy files to folder
  33.   foreach (@Gel_List){
  34.     copy($_,"$Dest_Dir_Gel\$Dir_Name");
  35.   }
  36.  
  37.   #copy  files to  folder
  38.   foreach (@Res_List){
  39.     copy($_,"$Dest_Dir_Res\$Dir_Name");
  40.   }
  41.  
  42.  closedir(cDIR);
  43.  }
  44. }
  45.  
  46. &dir_read($Src_Dir);
Jul 2 '08 #3
nithinpes
410 Expert 256MB
The variable $Dir_Name is causing the problem. You are passing $Src_Dir as argument to dir_read subroutine. Hence, the line,
Expand|Select|Wrap|Line Numbers
  1.  my $Dir_Name = $_[0];
  2.  
will assign 'C:\Documents and Settings\abcd' to $Dir_Name. So, the line
Expand|Select|Wrap|Line Numbers
  1. mkdir "$Dest_Dir_Gel\$Dir_Name";
  2.  
will be like mkdir "C:\gel\C:\Documents and Settings\abcd" :(

process the argument for read_dir() to get only the desired string as sub-folder structure.
Jul 3 '08 #4

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

Similar topics

3
by: John Bowman | last post by:
I need to copy a directory to another locaiton. Is there some .Net framework method I cannot find for copying a directory from 1 location to another? I found the File.Copy(), but there does not...
8
by: Ram Baruch | last post by:
Hi, I'm trying to use the File.Copy() function. It works well when the desenation file is local (Like: C:\dest\dest.exe). The problem is that when I'm trying to copy to a destenation that starts...
4
by: Amos Soma | last post by:
Does anyone know the easiest way, in C#, to copy all directories and files starting with some root directory? For example, how might I copy all files and directories starting with 'C:\Program...
1
by: Framework fan | last post by:
Hello. If I created a .NET solution called say MySol, how can I make a copy of this *entire* solution (project folders, files, everything) and create a second copy of this somewhere else on my...
10
by: Martin Ho | last post by:
I am running into one really big problem. I wrote a script in vb.net to make a copy of folders and subfolder to another destination: - in 'from.txt' I specify which folders to copy - in...
0
by: bradford.bret | last post by:
Is there a way to use .NET to extract the directories and files out of a .zip file. I have a folder with many (hundreds) of .zip files, and since you can just open them in explorer and copy out...
2
by: Alan Bak | last post by:
HI I am running Active Perl on a Windows XP machine. I am hoping to get some advise on a strategy to monitor and copy files that are arriving in a directory and need to be copied to a second...
4
by: supriyamk | last post by:
Hi, I am trying to search a directory for subdirectories, recreate the subdirectories elsewhere and copy only certain files from current subdirectory to new subdirectory. In other words i am...
1
by: skygremlin | last post by:
I am trying to write a simple VB app to copy all directories and files off a thumb drive to a directory on a pc. I have a couple things I am trying to automate. Final Build will: - Have...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.