Post by Frank SteinmetzgerWell, 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.
Mpv or Vlc on Windows will probably just workâ¢, too.
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Â
Now youâre talking about double-clicking in a file manager and open the
registered application. Thatâs the sameâto some extentâon Linux file
managers. I was referring to an application that could work out the details.
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.Â
Well, ther is the `file` tool, plus maybe `mediainfo` or `identify` for
images. But their output may not always be sufficient.
Post by Frank SteinmetzgerIf 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.
Hmmmm. I get a little of that but then I get lost.
The script first checks wheter it receives exactly two arguments, and exits
otherwise. In theory it should also check whether both paths exist and are
files. First rule of programming: always sanitise your inputs!
Now it gets the extension of the source file and the base part (i.e.
everything without the extension) from the destination. Then it deletes the
original destination file and finally moves the source by concatenating the
original destinationâs base part with the sourceâs extension part.
 Just how does that work and how would I use it?
I have a lot of little helper scripts. I collect them in ~/usr/bin, to which
my PATH is expanded in ~/.bashrc with export PATH=~/usr/bin:$PATH. Actually,
I keep the script files in git repositories under ~/dev, and then put
symlinks into ~/usr/bin, which point to the repository file.
I think I would save that as a file, make it executable and then run it
with whatever name I give it.
Exactly.
I'm not sure exactly how to tell it what files to move tho. Same as mv
maybe?Â
Yes. You give it two arguments. Thatâs what $1 and $2 are for in the script.
I always write my scripts so that they can handle spaces in filenames. I
find it an anachronism to still use underscores or dots in filenames where
spaces would go in normal language. File systems have been able to deal with
spaces for decades now.
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.Â
Thatâs the proper way to do it. I also have a root console open all the
time, but donât do normal file operations in there. The risk is too big that
I may be typing too fast for my own good.
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
Main Directory #Permanent location for files ----- Sub-directoryÂ
#Temporary location for files needing names changed etc. Once done, they
move up to main directory.
I donât quite understand the formatting of that line. But basically, you
have a directory for your videos, and in a subdiractory of that, you collect
your temporary files?
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>
OK. That could actually be automated in a way. How many files per directory
are we talking about? Because one approach I can think of is a managament
script. It goes through all the files in your temp subdir, and for each file
it asks you which file to overwrite in the main directory. It then moves the
file, but keeps the extension as in my first script. But this isnât
practical if there are dozens of files in the main dir, because you would
have to scroll through the big selection ist.
As an example, letâs assume we have the following file tree:
main
âââ episode 1.mkv
âââ episode 2.mpeg
âââ episode 3.avi
âââ temp
âââ episode 2 with better quality.mkv
You cd into main, and start the script. It checks for the presence of the
temp dir and, if it exists, asks for each of its files what to do:
main$ VideoCleanupScript
Select file to overwrite with 'episode 2 with better quality.mkv':
1) episode 1.mkv
2) episode 2.mpeg
3) episode 3.avi
#? 2
Removing 'episode 2.mpeg'
Moving file 'episode 2 with better quality.mkv' -> 'episode 2.mkv'
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. :/
I could write the above script in probably half an hour. Just say when. ;-)
I, too, have a few scripts that move files around. For example when I edit
photo albums, I do a final re-encoding of those images in different JPEG
quality levels as a trade-off between quality and storage space. For that I
have a script that asks me which level to keep whilst I look at the
different versions in a viewer. I then decide for one and the script picks
the appropriate file and moves it into the final folder. The other choices
are moved away so that if I halt the script midway, I can call it again and
pick up where I left it.
--
GrÃŒÃe | Greetings | Salut | Qaplaâ
Please do not share anything from, with or about me on any social network.
Of all the people Iâve met youâre certainly one of them.