New Posts  All Forums:Forum Nav:

Recursive Move - Page 2

post #11 of 27
Thread Starter 
You're doing the move in perl?

Here's what I was gonna do.
find . -name *.<extension> will list all the files recursively
Pipe that into a perl script to change the path name from
"./whatever" to the actual full path
Pipe that into the mv command. My problem is that I don't think pipe works the way I think it does
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #12 of 27
Works. Moved everything I needed.

Code:
#!/usr/bin/perl


use warnings;
use strict;

#print ("Must enter full path. EX) /home/user/  NOT) ~/\
\
");
#print ("Enter the directory path to the one you wish to search in.\
=>  ");
#my $o_dir = <STDIN>;
#chomp ($o_dir);

#print ("Enter final move location\
=> ");
#my $f_dir = <STDIN>;
#chomp ($f_dir);

# $o_dir is the original directory
# $f_dir is the directory the files will be moved too
#
my $o_dir = "/home/michael/test";
my $f_dir = "/home/michael/test/final";
my $type = "mp3";  # Don't include the period at the beginning

my $list = `ls -R -1 $o_dir`;
print ("O: $o_dir\
F: $f_dir\
");
my @array = split(/\
/, $list);

my $mid; # The sub directory the file was under $o_dir
my $dir; # The full path to the directory the file is in
my $move; # Full path to the file to be moves
my $here; # Full path to where the file is to be moved

foreach my $m (@array){
if ($m =~ /:$|:\
$/){
$dir = $m;
chop ($dir);
$dir .= "/";
$mid = $dir;
        $mid =~ s/^$o_dir//;
$mid =~ s/[\\s*]/\\ /g;
my $temp = $f_dir."/".$mid;
`mkdir "$temp"`;
#print ("$dir\
");  # For debugging
#print ("$mid\
");  # For debugging
}elsif ($m =~ /\\.$type$|\\.$type\
$/){
my $file = $m;
$file =~ s/[\\s*]/\\ /g;
$move = $o_dir."/".$mid.$file;
$here = $f_dir."/".$mid;
print ("MOVE $move\
HERE: $here\
"); # For debugging
`mv "$move" "$here"`;
}
}
Edit:
Improved a bit. Just change the scalar variable $type to the type of file you want to search for, and $o_dir and $f_dir to their corrosponding directories.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #13 of 27
Thread Starter 
Very nice. One change I would make to it at a glance. If you use Getopt::Long you can insert
GetOptions("t=s" => \\$type);
This will look for -t --t t or any of a few other variations. The next argument it looks for is a string (use s for string, i for int etc) and store it in the type variable

**EDIT**
The directories it uses are hard coded in. I changed that line to this
GetOptions("t=s" => \\$type, "s=s" => \\$o_dir, "d=s" => \\$f_dir);
Now you can specify the type with -t, the source with -s and the destination with -d

I'm going to go through the code tonite and tweak it a bit for my needs. I'll upload a version that takes a string or a filetype and defaults to the cwd
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #14 of 27
Thread Starter 
I feel like an idiot now
find <source dir> -name *.m4a
lists all .m4a files with their full pathnames. All I have to do now is get it to pipe into mv
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #15 of 27
mv $(find <source dir> -name *.m4a ) <TARGET>
Atlantis
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Athlon(tm) 64 X2 Dual Core Processor 6400+ Asus M2N-SLI deluxe bfg tech geforce 7600 gt oc 1 GB corsair xms ddr2 
Hard DriveOSMonitorKeyboard
80 GB sata +320 GB sata Gentoo:win2k3 ACER micro wireless 
PowerCaseMouse Pad
350w need 600w TT sviking the "blue mouse pad" 
  hide details  
Reply
Atlantis
(13 items)
 
  
CPUMotherboardGraphicsRAM
AMD Athlon(tm) 64 X2 Dual Core Processor 6400+ Asus M2N-SLI deluxe bfg tech geforce 7600 gt oc 1 GB corsair xms ddr2 
Hard DriveOSMonitorKeyboard
80 GB sata +320 GB sata Gentoo:win2k3 ACER micro wireless 
PowerCaseMouse Pad
350w need 600w TT sviking the "blue mouse pad" 
  hide details  
Reply
post #16 of 27
Thread Starter 
And General comes to the rescue
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #17 of 27
Thread Starter 
That doesn't work :|
It breaks up the filename by spaces and tries to move each word
so when it gets to
Somebody - something.m4a
it tries to move
Somebody
and
something.m4a
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #18 of 27
Edit; Nm
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
post #19 of 27
Thread Starter 
What does it output? Is it doing the same thing it is for me?
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
It goes to eleven
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6300 DS3 EVGA 8600GTS 2GB XMS2 DDR2-800 
Hard DriveOSMonitorKeyboard
1.294 TB Arch Linux/XP Samsung 226bw Eclipse II 
PowerCaseMouse
Corsair 520HX Lian-Li v1000B Plus G7 
  hide details  
Reply
post #20 of 27
Quote:
Originally Posted by rabidgnome229 View Post
What does it output? Is it doing the same thing it is for me?

Yeah same thing was happening to me.
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
BlackMesa
(14 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 Gigabyte XFX RF460 16gb G.Skill 
Hard DriveHard DriveOSMonitor
OCZ Vertex2 Sata II Coorsair Force GS Sata III Debian (testing) Shimian 27" 
KeyboardMouse
Filco w/ blue cherries Who needs a mouse? 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix