1 |
Frank Steinmetzger wrote: |
2 |
> Am Sun, Oct 23, 2022 at 01:35:55AM -0500 schrieb Dale: |
3 |
> |
4 |
>> Well, I ran into a slight problem. This isn't much of a problem with |
5 |
>> Linux but I'm not sure how this would work on windoze tho. The problem, |
6 |
>> if it is one, is the file extension. Let's say I have a mp4 file that |
7 |
>> is the older original file that I intend to replace. If the file I |
8 |
>> intend to put in its place is a .mkv file, mv uses the .mp4 extension |
9 |
>> because all it cares about is the name of the file, not what it is or |
10 |
>> its content. So, I end up with a .mkv file that has a .mp4 extension. |
11 |
>> It works here on Linux but not sure about windoze and such. |
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 |
> If you still want to stick to a terminal solution akin to mv, then there is |
25 |
> no way around a little script which wraps mv by extracting the extension and |
26 |
> filename base. You could also add some “intelligence” with regards to |
27 |
> directories, in order to reduce the amount of effort required to use the |
28 |
> command—in case your directories follow some schema or are constant. |
29 |
> |
30 |
> |
31 |
> #!/usr/bin/sh |
32 |
> |
33 |
> [ "$#" -ne "2" ] && exit 1 |
34 |
> SRC="$1" |
35 |
> DST="$2" |
36 |
> |
37 |
> SRC_EXT="${SRC##*.}" |
38 |
> DST_BASE="${DST%.*}" |
39 |
> |
40 |
> # remove destination for the case that the extensions differ |
41 |
> rm "$DST" |
42 |
> |
43 |
> mv "$SRC" "${DST_BASE}${SRC_EXT}" |
44 |
> |
45 |
|
46 |
I finally got a chance to try this. I saved it and made it executable. |
47 |
It runs but gave me this error. |
48 |
|
49 |
|
50 |
dmv torrent/video_name-old-place.mp4 video-name-new-place.mp4 |
51 |
bash: /bin/dmv: /usr/bin/sh: bad interpreter: No such file or directory |
52 |
dale@fireball ~/Desktop/Crypt/Series $ |
53 |
|
54 |
|
55 |
My scripting skills are minimal at best. Still, I kinda got what your |
56 |
script was doing. Those who have known me for a while understand how |
57 |
miraculous that is. ROFL I did some googling. It seems to not be able |
58 |
to find the 'shebang' part. Sure enough, sh isn't located in /usr/bin |
59 |
here. It's in /bin tho. I edited that line so it can find it. When I |
60 |
tried it, it worked but noticed another problem. It was leaving out the |
61 |
dot, ".", before the extension. Back into the script I went. I revved |
62 |
up my gears for a bit and made a edit. When I tried it again, I was |
63 |
shocked. I almost fell in the floor. Dang thing worked perfectly with |
64 |
me only having to edit once. I really did get how the script works, |
65 |
sort of. O_O |
66 |
|
67 |
This is the script as shown by cat: |
68 |
|
69 |
|
70 |
root@fireball / # cat /bin/dmv |
71 |
#!/bin/sh |
72 |
|
73 |
[ "$#" -ne "2" ] && exit 1 |
74 |
SRC="$1" |
75 |
DST="$2" |
76 |
|
77 |
SRC_EXT="${SRC##*.}" |
78 |
DST_BASE="${DST%.*}" |
79 |
|
80 |
# remove destination for the case that the extensions differ |
81 |
rm "$DST" |
82 |
|
83 |
mv "$SRC" "${DST_BASE}.${SRC_EXT}" |
84 |
root@fireball / # |
85 |
|
86 |
|
87 |
I added a little . on that last line before the extension bit. I'm a |
88 |
happy camper. Only thing is, turns out both source and destination file |
89 |
have the same extension in this case. Still, I bet it will work. Then |
90 |
I thought of a way to test this. I just changed the extension on the |
91 |
destination file and did a move. I changed the .mp4 to .mkv on the |
92 |
destination. When I used your move script, it used the .mp4 extension |
93 |
from the original source file but used the old name. Perfect!! |
94 |
|
95 |
Hope this makes the point. THANK YOU MUCH!!!! |
96 |
|
97 |
Dale |
98 |
|
99 |
:-) :-) |