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.
Any decent shell scripters in the house?
Collapse
X
-
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)Comment
-
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: 415397976Comment
-
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.Comment
-
-
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 folderComment
-
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)/.
doneMike 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.Comment
-
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?Comment
-
Last edited by mikesouth; 05-15-2008, 07:45 AM.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.Comment
-
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.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); ?>
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, 07:47 AM.Comment
-
yes thats for copying not moving...I gave you a for...do loop that will do what you want
its a shell scriptMike 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.Comment
-
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.Comment
-
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 substrMike 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.Comment
-
http://www.linuxquestions.org/questi...-files-199134/
this might work:
for i in `find <directory> -type d`; do cp *.jpg $i; doneComment
-
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.Comment
-
save the code below into a file call it whatever you like and run it like so
python nameofscript.py foldertoprocess
-------------------------------
PHP Code:import os, os.path, sys destdir = "/destdir" os.system( "mkdir " + destdir ) for root, dirs, files in os.walk( sys.argv[1] ): for name in files: name = os.path.join(root, name) command = "mv \"" + name + "\" \"" + destdir + "\"" os.system( command )Comment
-
Holy .... abort.save the code below into a file call it whatever you like and run it like so
python nameofscript.py foldertoprocess
-------------------------------
PHP Code:import os, os.path, sys destdir = "/destdir" os.system( "mkdir " + destdir ) for root, dirs, files in os.walk( sys.argv[1] ): for name in files: name = os.path.join(root, name) command = "mv \"" + name + "\" \"" + destdir + "\"" os.system( command )Comment
-
Pretty sure this does what you want in Bash, try it outhttp://www.linuxquestions.org/questi...-files-199134/
this might work:
for i in `find <directory> -type d`; do cp *.jpg $i; doneComment
-
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!"
Comment
-
I USE IT AND STAND BY ITS FUNCTIONALITY. REGISTERED!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!"
Comment
-
yes it will dump everything into one folder... those were the specs asked forComment
-
Comment
-
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" doneComment



AIM: GrouchyGfy
Comment