Frank Steinmetzger wrote: > Am Sun, Oct 23, 2022 at 01:35:55AM -0500 schrieb Dale: > >> Well, I ran into a slight problem. This isn't much of a problem with >> Linux but I'm not sure how this would work on windoze tho. The problem, >> if it is one, is the file extension. Let's say I have a mp4 file that >> is the older original file that I intend to replace. If the file I >> intend to put in its place is a .mkv file, mv uses the .mp4 extension >> because all it cares about is the name of the file, not what it is or >> its content. So, I end up with a .mkv file that has a .mp4 extension. >> It works here on Linux but not sure about windoze and such. > It’s not a problem for as long as the application you open the file with > does its own detection. I.e. you feed mp4 to mpv, but it recognises by > itself that it’s mp4 and can handle it. > >> I looked at the man page and I don't see a way to tell it to retain the >> extension. I see something about suffix but I don't think that is >> related to this. If I just backspace and change the extension, it >> basically moves the file and I end up with both the old and new file. I >> wish I could write code and create a tool for this. :/ >> >> Is there a way to work around this problem? It works great except for >> losing the file extension. > If you still want to stick to a terminal solution akin to mv, then there is > no way around a little script which wraps mv by extracting the extension and > filename base. You could also add some “intelligence” with regards to > directories, in order to reduce the amount of effort required to use the > command—in case your directories follow some schema or are constant. > > > #!/usr/bin/sh > > [ "$#" -ne "2" ] && exit 1 > SRC="$1" > DST="$2" > > SRC_EXT="${SRC##*.}" > DST_BASE="${DST%.*}" > > # remove destination for the case that the extensions differ > rm "$DST" > > mv "$SRC" "${DST_BASE}${SRC_EXT}" >
I finally got a chance to try this. I saved it and made it executable. It runs but gave me this error. dmv torrent/video_name-old-place.mp4 video-name-new-place.mp4 bash: /bin/dmv: /usr/bin/sh: bad interpreter: No such file or directory dale@fireball ~/Desktop/Crypt/Series $ My scripting skills are minimal at best. Still, I kinda got what your script was doing. Those who have known me for a while understand how miraculous that is. ROFL I did some googling. It seems to not be able to find the 'shebang' part. Sure enough, sh isn't located in /usr/bin here. It's in /bin tho. I edited that line so it can find it. When I tried it, it worked but noticed another problem. It was leaving out the dot, ".", before the extension. Back into the script I went. I revved up my gears for a bit and made a edit. When I tried it again, I was shocked. I almost fell in the floor. Dang thing worked perfectly with me only having to edit once. I really did get how the script works, sort of. O_O This is the script as shown by cat: root@fireball / # cat /bin/dmv #!/bin/sh [ "$#" -ne "2" ] && exit 1 SRC="$1" DST="$2" SRC_EXT="${SRC##*.}" DST_BASE="${DST%.*}" # remove destination for the case that the extensions differ rm "$DST" mv "$SRC" "${DST_BASE}.${SRC_EXT}" root@fireball / # I added a little . on that last line before the extension bit. I'm a happy camper. Only thing is, turns out both source and destination file have the same extension in this case. Still, I bet it will work. Then I thought of a way to test this. I just changed the extension on the destination file and did a move. I changed the .mp4 to .mkv on the destination. When I used your move script, it used the .mp4 extension from the original source file but used the old name. Perfect!! Hope this makes the point. THANK YOU MUCH!!!! Dale :-) :-)