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.

That is true on Linux.  Most linux software could care less what the
extension is or if it even has one.  Heck, you could likely change a
.mp4 to .txt and it would open with a video player just by clicking on
it.  Thing is, if I share a file with someone who uses windoze, I'm not
sure if it would work the same way.  A wrong extension could cause
problems, either not opening at all or crashing something.  It's
windoze, one can't expect much.  ROFL 

I thought about looking to see if there is a way to "scan" a directory
and look at each file and if needed, change the extension to the correct
one.  Thing is, I couldn't write a fancy script if my life depended on
it.  I also looked into using Krename to do it but it refuses to change
a extension.  Doing it one file at a time manually puts me back to where
it is easier to change the file the old way.  Time consuming but works. 


>> 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}"
>


Hmmmm.  I get a little of that but then I get lost.  Just how does that
work and how would I use it?  I think I would save that as a file, make
it executable and then run it with whatever name I give it.  I'm not
sure exactly how to tell it what files to move tho.  Same as mv maybe? 

Currently, I move to the main directory that files are in when I am in
Konsole and running as my user, so file permissions don't switch to
root.  My process on file organizing goes a little like this.  I have a
set of videos that go together.  When I have a new version of one or
more videos, I place them in a sub-directory until they are named
properly or something so I can move to the main directory.  Like this:

Main Directory  #Permanent location for files
----- Sub-directory  #Temporary location for files needing names changed
etc.  Once done, they move up to main directory.


A typical command for mv would be like this.

mv sub-directory/<file name of new file> <file name of old file in main
directory>

Just trying to follow this and figure out how to use it.  ;-)  I've said
this before, my scripting skills are so small it isn't funny.  :/

Dale

:-)  :-) 

Reply via email to