LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-03-2006, 09:02 AM   #1
New2Linux06
LQ Newbie
 
Registered: Apr 2006
Posts: 7

Rep: Reputation: 0
Having problem on sorting my files to the correct folder


I have the following files in mixed folder:
abc.mp3,xyz.mp3 logo.png ,fun.exe

After running the script it will sort the files in alphaetically order with prefix number.

music folder will have:
1-abc.mp3
2-xyz.mp3

picture folder will have:
1-logo.png

But when i run the script,it prompt me error
The error is:
mv: specified target, `gameassets/music' is not a directory

Below is the script:
#!/bin/bash
echo "Moving your file to correct folder."

for (( index=0; index < ${#types[@]}; index++ )); do
echo mv *.${types[$index]} ${types[$index]};
done

mv *.mp3 --target-directory=gameassets/music
mv *.png --target-directory=gameassets/picture
mv *.exe --target-directory=gameassets/exe_files

end of script

If anyone know my mistake,please highlight it to me.
Thanks
 
Old 11-03-2006, 09:45 AM   #2
Wells
Member
 
Registered: Nov 2004
Location: Florida, USA
Distribution: Debian, Redhat
Posts: 417

Rep: Reputation: 53
Have you tried putting the full pathname in for the target directory? i.e. if "gameassets/music" is actually located in /home/foo/gameassets/music, try changing the line

"mv *.mp3 --target-directory=gameassets/music"

to

"mv *.mp3 --target-directory=/home/foo/gameassets/music"

On the other hand, if you are creating these directories for each game or whatever you are downloading seperately, the script needs to create the "gameassets" directory and the "music", "picture", and "exe_files" directory seperately before moving the data into those directories. As such, you would need the following commands before the mv statements:

mkdir gameassets
mkdir gameassets/music
mkdir gameassets/picture
mkdir gameassets/exe_files

This is because a mv statement cannot do deep creation of directories.
 
Old 11-03-2006, 09:54 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,803

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
You are not using absolute paths, so it will not work unless all the files are in the parent directory of gameassets/music, etc.

e.g. suppose that the absolute path is /home/username/gameassets/picture

To use you script, you would need a minimum of 3 things:
-- All the files would have to be in /home/username
-- The target directories must already exist
-- The script would have to be run in /home/username
 
Old 11-04-2006, 05:22 AM   #4
New2Linux06
LQ Newbie
 
Registered: Apr 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks,now that i have successfully move the files to correct folder
But the naming is wrong

after moving the mp3 files to music folder,it look like this:
1-abc.mp3
1-xyz.mp3

but i want it to be like this:
1-abc.mp3
2-xyz.mp3

I use variable filecount to count the total number of mp3 it have so that it in music folder,it will display 1-abc.mp3 , 2-xyz.mp3

Below are the script:

#!/bin/bash

for filename in *.mp3
do
filecount="$( find . -name '*.mp3' | wc -l)"

for ((i=1; i<=$filecount; i++))
do
echo -n "$i-.."

echo "Moving your $filename to music folder."
mv $filename /root/gameassets/music/$i-$filename
done
done

The error it display when i run this script:
1-..Moving your abc.mp3 to music folder.
2-..Moving your abc.mp3 to music folder.
mv: cannot stat `abc.mp3': No such file or directory
1-..Moving your xyz.mp3 to music folder.


May I know how come the Moving your abc.mp3 is repeat twice?

Please point out my mistakes.
Thanks

Last edited by New2Linux06; 11-04-2006 at 05:30 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling in any folder will install in current or correct folder ? anjanesh Fedora 4 05-10-2006 09:44 AM
sorting the same kind of files in a folder? lenny45 MEPIS 11 05-08-2006 12:45 PM
Sorting files in BASH deleted/ Linux - Newbie 16 01-26-2006 07:03 AM
HELP, sorting files by name with environment ar3ol Linux - Newbie 6 12-05-2005 05:03 PM
size of shared folder not correct VMWare buldir Linux - Software 0 09-01-2004 05:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration