473,700 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to filter recordset for a copy file script

2 New Member
Created perl script to query oracle db to get directory path and file name. The script will form an UNC path to copy file to appropriate directory via a while statement and foreach loop. Script works just fine which copies one file at a time. I think it would be more efficient if I can identify if I had multiple files that go to same directory, which would be the case 99.9% of the time. Sometimes I would have 1000+ files that need to copy to one directory (dir1) and maybe 200 files to another directory (dir2) and maybe 100 files to another directory (dir3) in one instance.
I query the db, use a fetchrow_array in a while statement that strips off one row at a time.
How can I filter the recordset to get the files for dir1, dir2 or dir3?
Jul 17 '12 #1
2 2352
BigSky
2 New Member
I believe I figured it out. I just need to interweave code to original script.
Expand|Select|Wrap|Line Numbers
  1. while ( $fpn = $sthpathnames->fetchrow_arrayref) {
  2.     push @pathfiles, [ @$fpn ];
  3. }    
  4. die "Fetch failed due to $DBI::errstr" if $DBI::err;
  5.  
  6. foreach $pathfile ( @pathfiles ) {
  7.     push @filepaths, @$pathfile[0];
  8.     #print "@$pathfile[0]\n";
  9. }
  10. my %unqpath = ();
  11. my @unqpath = grep { ! $unqpath{ $_ }++ } @filepaths;
  12. foreach $unqpath ( @unqpath ) {
  13.     foreach $pathfile ( @pathfiles ) {
  14.         if ( $unqpath eq @$pathfile[0] ) {
  15.             #print "$unqpath and @$pathfile[1]\n";
  16.             my $filequote = '"' . @$pathfile[1] . '" ';
  17.             push @filequotes, $filequote;
  18.         }        
  19.     }
  20.     foreach ( @filequotes ){
  21.         print "$_\n";
  22.     }
  23.     print "path $unqpath and files @filequotes\n";
  24.     @filequotes = ();
  25. }
  26.  
Jul 17 '12 #2
numberwhun
3,509 Recognized Expert Moderator Specialist
Mind you I have only given this a minute or so of thought, but here is what I think. You could make a hash of arrays. The keys of the hash can be the path's and the values for each key can be an array of file names that you would push new values on to. Once completed, you could take process each key/value set using the key as the path (which it is) and the array of values as the file names to move.

Regards,

Jeff
Jul 17 '12 #3

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

Similar topics

3
86469
by: Kay Lee | last post by:
Hi, I looked up os module to find out some method to move and copy files in python, but os doesn't support such methods. Is there any way to move & copy files in python? Thanks in adv.
0
530
by: durumdara | last post by:
Hi ! I have some backup files on a server farm. I want to store these local backup files on a backup file server for "safety's snake". These files are compressed zip files with 12 character length password. But my system admin asked me, how can I improve the safety of the copy operation, and the storing (now I use Samba share to store these files. I map the SMB share on the client, copy these files, and unmap SMB).
1
2748
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 server". But i don't know how to deal with this. Do you have any example code or hint? I appreciate in advance!
8
6205
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 Server2 and visa-versa. The 2 server are running 2003. It's a form-based authentication (.NET 1.1) site and I'm using IIS 6 native mode. Both boxes are set to the same workgroup. Since everything is so locked down now, I'm not sure what's the...
2
5584
by: Xavier Valdés | last post by:
Hi all, I would like to copy FILES from the clipboard to a desired folder from VB.NET. I was able to copy files (with filedrop data format) to the clipboard but I don't know how to catch this data (the entire data) and leave it (copy it) to a folder. It doen't matter if the data I want to copy is a folder, a file or a group of them. The fact is I would like to copy the WHOLE data with a function.
11
18182
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 behavior if I just used File.Copy... The files are relatively small.
4
11731
by: sajid_yusuf | last post by:
Hi I am trying to develop a Windows service in VB.NET which has timer enabled and keeps checking a folder (or group of folders) for any new file or changed files. As soon as it detects any new file or changes (to files or folders) then it copies the files (and any new folders) to a folder in the mapped network drive. So far I have been successful in developing and deploying the service which works on my local machine with two drives...
1
4150
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, these will be the names of two directories. This time, make sure that the "sending" directory exists (and is, indeed, a directory). Make sure that the "receiving" directory exists, and if not, create it. Then, copy files from the sending directory to...
3
17018
by: =?Utf-8?B?U2Vhbk1hYw==?= | last post by:
How do I programmatically copy files across a network (from a local workstation to another local workstation on the network) using visual basic 2005? In other words, when in explorer and you enter a unc path to a network workstation, you are prompted with a dialog box asking for the user name and password that has access rights to that computer. After validating, you can access the files on the remote pc just like you can on your own pc,...
2
3216
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 files from mapped drive to my machine but when I tried to copy over to different machine throws me an error: Please help me recrify Here is my perl script as follows:
0
9204
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9060
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8914
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6557
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4650
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2380
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2021
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.