Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 05-15-2008, 08:01 AM   #1
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
Any decent shell scripters in the house?

I have a directory 'x' that I need to to move all .jpg's from and put them into another folder. The directory 'x' has many other folders inside of it so this will need to be a recursive string. Who can help? I'll throw you a bone via paypal or something if needed.
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:04 AM   #2
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
btw this is for freebsd/bash
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:13 AM   #3
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
come on peoples.. wheres fuzebox/rob
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:28 AM   #4
ScriptWorkz
Confirmed User
 
Industry Role:
Join Date: Jul 2007
Location: Intraweb
Posts: 274
if you can run a php script to do it i could help you out (i generally use php instead of sh for most shell scripts anyway, so i'm pretty rusty on actual sh scripting)
ScriptWorkz is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:31 AM   #5
videodoll
Confirmed User
 
videodoll's Avatar
 
Join Date: Sep 2006
Location: here and there.
Posts: 196
I think that is very simple to do without a script unless i don't understand what you want.
__________________

www.nikki9teen.com
www.amandaedge.com

ICQ: 415397976
videodoll is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:31 AM   #6
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
I probably could use a php script
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:34 AM   #7
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
directory 'x' has many sub directories within it each with multiple .jpg's

I basically want to move (or copy if needed) all .jpg's from within these sub directories into one directory 'y' so that 'y' contains all .jpg's from 'x' and it's sub directories.
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:34 AM   #8
ScriptWorkz
Confirmed User
 
Industry Role:
Join Date: Jul 2007
Location: Intraweb
Posts: 274
just tried to hit you on icq, i can help you out, just have a few quick questions
ScriptWorkz is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:35 AM   #9
scriptdog
Registered User
 
Join Date: May 2008
Location: Monterrey, Mexico
Posts: 3
hello, i can do that, just explain me..

you have a tree where you want to take all jpgs out and put it where?

i just need that you can run a php, if you have a webserver in that machine is very easy to do, if not we just have to download a php and unzip it in any folder
scriptdog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:37 AM   #10
mikesouth
Confirmed User
 
mikesouth's Avatar
 
Industry Role:
Join Date: Jun 2003
Location: My High Horse
Posts: 6,334
this is gonna be close

find (top level directory) / -name *.jpg -print | mv (new directory)

that should start you that may recreate the structure of the original dir ( i dont remember for sure)

if so you can put it in a for x in loop something like this

for x in `ls -1 -r (top level directory)/*.jpg`
do
mv x (newdirectory)/.
done
__________________
Mike South

It's No wonder I took up drugs and alcohol, it's the only way I could dumb myself down enough to cope with the morons in this biz.
mikesouth is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:38 AM   #11
ScriptWorkz
Confirmed User
 
Industry Role:
Join Date: Jul 2007
Location: Intraweb
Posts: 274
do you want jpg's in subdirectories of x to show up in corresponding subdirectories in y or just in the top level y folder?
ScriptWorkz is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:40 AM   #12
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
I don't want it to create any sub directories in 'y' just dump ALL jpg's from 'x' and recursive directories
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:44 AM   #13
mikesouth
Confirmed User
 
mikesouth's Avatar
 
Industry Role:
Join Date: Jun 2003
Location: My High Horse
Posts: 6,334
Quote:
Originally Posted by jdavis View Post
I don't want it to create any sub directories in 'y' just dump ALL jpg's from 'x' and recursive directories
this'll do it

for x in `ls -1 -r (top level directory)/*.jpg`
do
mv $x (newdirectory)/.
done
__________________
Mike South

It's No wonder I took up drugs and alcohol, it's the only way I could dumb myself down enough to cope with the morons in this biz.

Last edited by mikesouth; 05-15-2008 at 08:45 AM..
mikesouth is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:45 AM   #14
ScriptWorkz
Confirmed User
 
Industry Role:
Join Date: Jul 2007
Location: Intraweb
Posts: 274
PHP Code:
#!/usr/bin/php
<?
// set $base_dir to the source dir, and $dest_dir to where you want files moved too, include trailing /
$base_dir = "/source/dir/";
$dest_dir = "/dest/dir/";

// function for recursion
function process_dir($dir) {
    global $dest_dir;
    
    $d = opendir($dir);
    
    while (($f = readdir($d)) !== FALSE) {
        if (strcmp($f, ".") && strcmp($f, "..")) {
            if (is_dir($dir . $f)) {
                process_dir($dir . $f);
            } else if (is_file($dir . $f)) {
                $tmp = explode(".", $f);
                $ext = strtolower($tmp[(count($tmp) - 1)]);
            
                if (!strcmp($ext, "jpg") || !strcmp($ext, "jpeg")) {
                    // to copy files
                    copy($dir . $f, $dest_dir . $f);
                
                    // uncomment to move files instead, comment above
                    // rename($dir . $f, $dest_dir . $f)
                }
            }
        }
    }
    
    closedir($d);
}

process_dir($base_dir);
?>
i didn't test it, but if you save that as say move-pics.php and chmod it +x then ./move-pics.php it should do the trick. if you want files moved instead of copied, look at the comments and comment the copy line out and remove the commenting on the rename line. you also need to make sure the shebang at the top points to your php binary and the $base_dir and $dest_dir variables are set to your x and y directories respectively.

EDIT: just saw mike souths post, as a shell script that'd probably work a little easier then mine, atleast you have a backup.

Last edited by ScriptWorkz; 05-15-2008 at 08:47 AM..
ScriptWorkz is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:50 AM   #15
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
thanks for the suggestions. what about this, i realize it's for copying and not moving

find $SRC -iname '*.jpg' -exec cp '{}' ${DEST}/ \;
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:52 AM   #16
mikesouth
Confirmed User
 
mikesouth's Avatar
 
Industry Role:
Join Date: Jun 2003
Location: My High Horse
Posts: 6,334
yes thats for copying not moving...I gave you a for...do loop that will do what you want

its a shell script
__________________
Mike South

It's No wonder I took up drugs and alcohol, it's the only way I could dumb myself down enough to cope with the morons in this biz.
mikesouth is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:52 AM   #17
scriptdog
Registered User
 
Join Date: May 2008
Location: Monterrey, Mexico
Posts: 3
god bless linux
scriptdog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:53 AM   #18
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
I would prefer to have it not overwrite files with the same name but that gets more complicated
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 08:56 AM   #19
mikesouth
Confirmed User
 
mikesouth's Avatar
 
Industry Role:
Join Date: Jun 2003
Location: My High Horse
Posts: 6,334
Quote:
Originally Posted by jdavis View Post
I would prefer to have it not overwrite files with the same name but that gets more complicated
not really just add a counter variable in the loop and append it to the filename
__________________
Mike South

It's No wonder I took up drugs and alcohol, it's the only way I could dumb myself down enough to cope with the morons in this biz.
mikesouth is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 09:00 AM   #20
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
Quote:
Originally Posted by mikesouth View Post
not really just add a counter variable in the loop and append it to the filename
do it up
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 09:47 AM   #21
mikesouth
Confirmed User
 
mikesouth's Avatar
 
Industry Role:
Join Date: Jun 2003
Location: My High Horse
Posts: 6,334
my shell scripting is a tad rusty and I dont have man pages here but
a=0
for x in `ls -1 -r (top level directory)/*.jpg`
do
a++
mv $x (newdirectory)/$x$a.jpg
done

will be on the right track though you may have to snip out the first .jpg with a substr command if that gives you .jpg twice (and I think it will) Im flying by the seat of my pants here but you get the gist yer on a UNIX system (or derivative) use man pages for substr for the syntax

man substr
__________________
Mike South

It's No wonder I took up drugs and alcohol, it's the only way I could dumb myself down enough to cope with the morons in this biz.
mikesouth is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-15-2008, 09:54 AM   #22
Socks
Confirmed User
 
Industry Role:
Join Date: May 2002
Location: Toronto
Posts: 8,475
http://www.linuxquestions.org/questi...-files-199134/

this might work:

for i in `find <directory> -type d`; do cp *.jpg $i; done
Socks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 05:35 AM   #23
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
OK people $50 to the first person that gives me this script. I think mikesouth is closest to what I'm looking for but it needs to be a script that doesn't need me hacking it to get it working. I would prefer not to have a php script, just a plain old bash one like Mike is proposing. It must not rewrite other .jpgs with the same name but instead rename the file names incrementally if it spots duplicates.
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 05:40 AM   #24
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
BTW, I am not available on ICQ today..
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 07:09 AM   #25
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
bump to give someone money
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 08:11 AM   #26
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
bump, would like to have this script in my hand today
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 08:28 AM   #27
scoremoola
Registered User
 
scoremoola's Avatar
 
Join Date: May 2008
Location: miami,fl
Posts: 79
save the code below into a file call it whatever you like and run it like so
python nameofscript.py foldertoprocess
-------------------------------

PHP Code:
import osos.pathsys

destdir 
"/destdir"

os.system"mkdir " destdir )

for 
rootdirsfiles in os.walksys.argv[1]  ):
    for 
name in files:
            
name os.path.join(rootname)
            
command "mv \"" name "\" \"" destdir "\""
            
os.systemcommand 
__________________

www.GetSCORECash.com
lando | icq: 337-369-506
I wasn't born as much as I fell out
scoremoola is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 08:39 AM   #28
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
Have you tested it out? Will it dump all .jpg files into ONE directory 'y' without overwriting existing files with the same name?
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 08:39 AM   #29
mrkris
Confirmed User
 
Join Date: May 2005
Posts: 2,737
Quote:
Originally Posted by scoremoola View Post
save the code below into a file call it whatever you like and run it like so
python nameofscript.py foldertoprocess
-------------------------------

PHP Code:
import osos.pathsys

destdir 
"/destdir"

os.system"mkdir " destdir )

for 
rootdirsfiles in os.walksys.argv[1]  ):
    for 
name in files:
            
name os.path.join(rootname)
            
command "mv \"" name "\" \"" destdir "\""
            
os.systemcommand 
Holy .... abort.
__________________

PHP-MySQL-Rails | ICQ: 342500546
mrkris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 08:43 AM   #30
Socks
Confirmed User
 
Industry Role:
Join Date: May 2002
Location: Toronto
Posts: 8,475
Quote:
Originally Posted by Socks View Post
http://www.linuxquestions.org/questi...-files-199134/

this might work:

for i in `find <directory> -type d`; do cp *.jpg $i; done
Pretty sure this does what you want in Bash, try it out
Socks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 08:45 AM   #31
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Jesus tapdancing Christ.
Code:
#!/bin/bash
TWIRLY1="|"
TWIRLY2="/"
TWIRLY3="-"
TWIRLY4="\"
DESTDIR=/tmp
WHEREFROM=/home
TWIRL=1
for n in `find $WHEREFROM -name \*.jpg -print`; do
TWIRL=$TWIRL+1
IF [ $TWIRL -gt 4 ]; then
  TWIRL=1
fi
COUNT=0
if [ -f $DESTDIR/$n ]; then
  # Ho ho ho.
  $newname = $RAND`basename $n`;
else
  $newname = `basename $n`;
fi
echo -n "Imma busy fuckkin up $newname, hold on..  $TWIRL"
mv $n $destdir/$newname
done
echo ""
echo "THIS SCRIPT IS SHAREWARE.  PLS REGISTER!"
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 08:54 AM   #32
mrkris
Confirmed User
 
Join Date: May 2005
Posts: 2,737
Quote:
Originally Posted by GrouchyAdmin View Post
Jesus tapdancing Christ.
Code:
#!/bin/bash
TWIRLY1="|"
TWIRLY2="/"
TWIRLY3="-"
TWIRLY4="\"
DESTDIR=/tmp
WHEREFROM=/home
TWIRL=1
for n in `find $WHEREFROM -name \*.jpg -print`; do
TWIRL=$TWIRL+1
IF [ $TWIRL -gt 4 ]; then
  TWIRL=1
fi
COUNT=0
if [ -f $DESTDIR/$n ]; then
  # Ho ho ho.
  $newname = $RAND`basename $n`;
else
  $newname = `basename $n`;
fi
echo -n "Imma busy fuckkin up $newname, hold on..  $TWIRL"
mv $n $destdir/$newname
done
echo ""
echo "THIS SCRIPT IS SHAREWARE.  PLS REGISTER!"
I USE IT AND STAND BY ITS FUNCTIONALITY. REGISTERED!
__________________

PHP-MySQL-Rails | ICQ: 342500546
mrkris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 08:59 AM   #33
scoremoola
Registered User
 
scoremoola's Avatar
 
Join Date: May 2008
Location: miami,fl
Posts: 79
yes it will dump everything into one folder... those were the specs asked for
__________________

www.GetSCORECash.com
lando | icq: 337-369-506
I wasn't born as much as I fell out
scoremoola is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 09:08 AM   #34
HorseShit
Too lazy to set a custom title
 
Join Date: Dec 2004
Posts: 17,513
grouchyadmin, shoot me an email to area51 at gmail please
HorseShit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 09:47 AM   #35
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by jdavis View Post
grouchyadmin, shoot me an email to area51 at gmail please
Hi Justin.

I hit you up as requested.
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-16-2008, 09:51 AM   #36
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Oh, incidentally, this should actually do what you want without being quite so obnoxious. I don't trust having a 'smart' shell; just basic utilities that have been in UNIX since the 70s.

Code:
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin
FROMDIR=SET_BASEDIR_FOR_MOVE_FROM_HERE
TODIR=SET_DIR_TO_COPY_IT_TO_HERE
FILETYPE=jpg
APPENDSTART=1
for n in `find $FROMDIR -name \*.$FILETYPE -print`; do
   FILE=`basename "$n"`
   if [ -f "$TODIR/$FILE" ]; then
     while [ $APPENDSTART -le 100 ]; do
       APPENDSTART=`expr $APPENDSTART + 1`
       if [ ! -f "$TODIR/$APPENDSTART$FILE" ]; then
         FILE="$APPENDSTART$FILE"
         break;
       fi
     done
   fi
   echo "Moving '$n' to '$TODIR/$FILE'."
   mv "$n" "$TODIR/$FILE"
done
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.