Gentoo Archives: gentoo-user

From: Frank Steinmetzger <Warp_7@×××.de>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Dolphin and adding a option, if it exists.
Date: Sun, 23 Oct 2022 09:42:00
Message-Id: Y1UMWH5m4UtISJf3@tp
In Reply to: Re: [gentoo-user] Dolphin and adding a option, if it exists. by Dale
1 Am Sun, Oct 23, 2022 at 01:35:55AM -0500 schrieb Dale:
2
3 > Well, I ran into a slight problem.  This isn't much of a problem with
4 > Linux but I'm not sure how this would work on windoze tho.  The problem,
5 > if it is one, is the file extension.  Let's say I have a mp4 file that
6 > is the older original file that I intend to replace.  If the file I
7 > intend to put in its place is a .mkv file, mv uses the .mp4 extension
8 > because all it cares about is the name of the file, not what it is or
9 > its content.  So, I end up with a .mkv file that has a .mp4 extension. 
10 > It works here on Linux but not sure about windoze and such.
11
12 It’s not a problem for as long as the application you open the file with
13 does its own detection. I.e. you feed mp4 to mpv, but it recognises by
14 itself that it’s mp4 and can handle it.
15
16 > I looked at the man page and I don't see a way to tell it to retain the
17 > extension.  I see something about suffix but I don't think that is
18 > related to this.  If I just backspace and change the extension, it
19 > basically moves the file and I end up with both the old and new file.  I
20 > wish I could write code and create a tool for this.  :/ 
21 >
22 > Is there a way to work around this problem?  It works great except for
23 > losing the file extension. 
24
25 If you still want to stick to a terminal solution akin to mv, then there is
26 no way around a little script which wraps mv by extracting the extension and
27 filename base. You could also add some “intelligence” with regards to
28 directories, in order to reduce the amount of effort required to use the
29 command—in case your directories follow some schema or are constant.
30
31
32 #!/usr/bin/sh
33
34 [ "$#" -ne "2" ] && exit 1
35 SRC="$1"
36 DST="$2"
37
38 SRC_EXT="${SRC##*.}"
39 DST_BASE="${DST%.*}"
40
41 # remove destination for the case that the extensions differ
42 rm "$DST"
43
44 mv "$SRC" "${DST_BASE}${SRC_EXT}"
45
46 --
47 Grüße | Greetings | Salut | Qapla’
48 Please do not share anything from, with or about me on any social network.
49
50 “If you enjoy wasting time, is that time really wasted?” – Philosoraptor

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies

Subject Author
Re: [gentoo-user] Dolphin and adding a option, if it exists. Dale <rdalek1967@×××××.com>
Re: [gentoo-user] Dolphin and adding a option, if it exists. Dale <rdalek1967@×××××.com>