LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2009, 03:50 PM   #1
PiNPOiNT
LQ Newbie
 
Registered: Apr 2009
Posts: 15

Rep: Reputation: 0
changing to a specific folder, one deeper than specified location


I have a path

/mnt/accounts/local/MOVIES/MovieName/VIDEO_TS/

and i want to move everything from the VIDEO_TS folder, to the "MovieName" folder.

but sometimes the path might be longer
/mnt/accounts/local/MOVIES/MovieName/Season 1/Specials/VIDEO_TS/

However, it will always be the folder after "MOVIES"

is there a way i can parse the path and determine the MovieName no matter how long the path?
 
Old 04-27-2009, 04:36 PM   #2
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
Of course you can do that... but cp and mv both have recursive directives that will cause them to operate on the specified directory and all subdirectories.

If that isn't what you want for some reason, then the 'find' command will locate and detail the directories in a specified path (and there are other methods, as well, but that one, imo, is simplest).
 
Old 04-27-2009, 04:40 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Code:
#!/bin/bash

FIXED_PATH="/mnt/accounts/local/MOVIES/"
SOURCE_PATH="/mnt/accounts/local/MOVIES/MovieName/Season 1/Specials/VIDEO_TS/"

FIXED_PART_REMOVED="${SOURCE_PATH#$FIXED_PATH}"
FIXED_PART_REMOVED="${FIXED_PART_REMOVED#/}" # remove leading slash if it's there

MOVIE_NAME="${FIXED_PART_REMOVED%%/*}"
DESTINATION_PATH="${FIXED_PATH%/}/$MOVIE_NAME"
echo "To move: \"$MOVIE_NAME\" to $DESTINATION_PATH do:"
echo "  mv \"${SOURCE_PATH%/}/*\" \"$DESTINATION_PATH\""
 
Old 04-28-2009, 09:32 AM   #4
PiNPOiNT
LQ Newbie
 
Registered: Apr 2009
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks HKO

Your code works great, but i'm having one little problem at the end.

echo " mv \"${SOURCE_PATH%/}/*\" \"$DESTINATION_PATH\""

I've removed the echo and the quotes around the outside, and when i try and run it, it says

mv: cannot stat `"/mnt/accounts/local/MOVIES/MovieName/Season 1/Specials/VIDEO_TS/*"': No such file or directory

Is there some extra character getting in there that's messing up the mv command?

manually typing mv /MovieName/Season 1/Specials/VIDEO_TS/* /MovieName/ works as expected though.
I can't figure it out

Thanks for all of your help
 
Old 04-28-2009, 04:29 PM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
that is because the "season 1" part has a space in it. That is why there need to be double quotes around it. And that is also why I did the last echo command with those "\" things: so that when you run the script is the command as printed would work. A bit confusing, I now realize..

To actually do the copying inside the script just do:
Code:
mv "${SOURCE_PATH%/}/*" "$DESTINATION_PATH"
The paths with or without spaces in them should work.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Way to make autofs mount to specific USB flash drive to specific folder? utahnix Linux - Software 2 11-24-2010 05:27 PM
Changing directory default creation mask for specific folder - NOT samba. maginotjr Linux - General 3 01-21-2009 09:36 AM
very slow network - but only for one machine while used at a specific location wastingtime Linux - Networking 6 04-21-2008 04:32 PM
Untar File to a specific location ! Libu Linux - General 3 12-19-2005 07:14 PM
Mount hardware to specific location with specified device blixel Linux - Hardware 5 10-21-2003 04:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:44 AM.

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