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 |
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. |
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 |
All times are GMT -5. The time now is 10:51 PM. |