Having problem on sorting my files to the correct folder
Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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
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:
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.