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}"
--
Grüße | Greetings | Salut | Qapla’
Please do not share anything from, with or about me on any social network.
“If you enjoy wasting time, is that time really wasted?” – Philosoraptor
> 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}"
--
Grüße | Greetings | Salut | Qapla’
Please do not share anything from, with or about me on any social network.
“If you enjoy wasting time, is that time really wasted?” – Philosoraptor