I have a folder named "Video" on my Desktop and inside that folder are a bunch of .MTS video files. (00000.MTS, 00001.MTS, 00002.MTS etc...)
There is also a subfolder "H.265" (Video > H.265) which contains files (00000.mp4, 00001.mp4, 00002.mp4 etc...) which were made by converting the files from the parent folder. The problem is they don't contain the correct date created metadata.
I want to use the command
touch -r 00000.MTS 00000.mp4
touch -r 00001.MTS 00001.mp4
...
touch -r 000mn.MTS 000mn.mp4
to copy the date from the MTS to the mp4 file.
Is there a way I could write a for loop or something to do this for every single file?
I am using MacOS Mojave.
Something like this
cd ~/Desktop/Video
for v in *.mp4
do
vn=`basename $v .mp4`
touch -r "H.265/$vn.MTS" $v
done
Related
I have a .txt list of filenames that I would like to copy into a new folder. The filenames take the form: 0-01-199898988999.mp4. I can use the list of file names to copy files into a new folder using the following code.
cp `cat list.txt` new_folder/
However, this only works when the files I want to copy, the .txt file, and the new folder are all in the same directory, and all of my files to copy are organized into subfolders within the directory.
FolderA
->list.txt
->new_folder
->SubA
-->0-01-199898988999.mp4
-->0-02-199898988999.mp4
-->0-03-199898988999.mp4
->SubB
-->0-04-199898988999.mp4
-->0-05-199898988999.mp4
-->0-06-199898988999.mp4
-->0-06-199898988999.mp4
How can I modify the code to search through the subdirectories of folder A?
I've tried using --parents, but it hasn't worked.
cp -v --parents `cat list.txt` /new_folder
I've been searching around for answers, but most versions of this problem involve a list with the unique directory names for each file (which I don't have), copying all the files within the subdirectories, or searching by extension instead of file name.
Goal is to convert all .wav files to .mp3 in a different location.
The following code works, but creates output files in the same directory.
All the newly created .mp3's are right alongside the .wav's.
for file in /path/to/*.wav; do lame --preset insane "$file" "${file%.wav}".mp3; done
How can I use terminal to convert a drive full of .wav's with lame and output the .mp3's to a different drive? I've tried changing lame's output, but this syntax grabs the entire filename. Looking for the most simple solution.
From the lame manual, the synopsis is very straightforward:
lame [options] <infile> <outfile>
Found the basic concept here
Assuming that the output files should be placed to /output, possible to extend loop to calculate the output file name using the 'basename'
OUT=/output
for file in /path/to/*.wav; do
# Replace .wav with .mp3
out=${file%.wav}.mp3
# Remove directory (anything up to the last '/'
out=${file##*/}
lame --preset insane "$file" $OUT/$out
done
A Redditor had written me a great script that allowed me to move all the files in a series of folders into a new subdirectory in all those folders called New. However, I also have pre-existing folders (namely just 1 called "Journals") that have had their files moved into a subdirectory called New, as well.
How would I modify the following script (on Windows) to not touch any folders within the folders, or perhaps not touch any folder called Journals?
For example, the current directory looks like:
Parent/Folder name/tons of files/
Parent/Folder name/Journals/tons of files
(folder name = random string of alphanumeric numbers in the thousands). Each folder has a ton of files, and a folder called Journals.
I would like:
Parent/randomstring folder/New/tons of files/
Parent/randomstring folder/Journals/tons of files
The code they wrote for me:
# Run from search root
cd "O:\..."
# Change this to taste
export NEWDIR=New
find . | egrep '(mp4$|jpg$|png$)' |
while read FILE
do
BASEDIR=$(dirname "$FILE")
mkdir "$BASEDIR/$NEWDIR" > /dev/null 2>&1
mv "$FILE" "$BASEDIR/$NEWDIR"
done
This code would do the following:
Parent/randomstring folder/New/tons of files/
Parent/randomstring folder/Journals/new/tons of files
Im currently using tags such as exiftool -FileModifyDate(<)datetimeoriginal, etc. in terminal/cmd...
Im switching from icloud and the dates in the metadata are exif (meaning finder and windows explorer just see the date they were downloaded)..
It's working but for any sloMo videos that are M4V, they dont change.. I have the originals which do have the right dates and was wondering if there is a way to match file names (123.mp4 = 123.m4v) and copy the metadata over... But I also want to do it in batches. (since every month I will be offloading my iphone every month or so) Thanks!
It will depend upon your directory structure, but your command should be something like this:
exiftool -TagsFromFile %d%f.mp4 "-FileModifyDate<datetimeoriginal" -ext m4v DIR
This assumes the m4v files are in the same directory as the mp4 files. If not, change the %d to the directory path to the mp4 files.
Breakdown:
-TagsFromFile: Instructs exiftool that it will be copying tags from one file to another.
%d%f.mp4: This is the source file for the copy. %d is a exiftool variable for the directory of the current m4v file being processed. %f is the filename of the current m4v file being processed, not including the extension. The thing to remember is that you are processing m4v files that are in DIR and this arguments tells exiftool how to find the source mp4 file for the tag copy. A common mistake is to think that exiftool is finding the source files (mp4 in this case) to copy to the target files (m4v) when exiftool is doing the reverse.
"-FileModifyDate<datetimeoriginal": The tag copy operation you want to do. Copies the DateTimeOriginal tag in the file to the system FileModifyDate.
-ext m4v: Process only m4v files.
Replace DIR with the filenames/directory paths you want to process. Add -r to recurse into sub-directories. If this command is run under Unix/Mac, reverse any double/single quotes to avoid bash interpretation.
I need a solution for this script to move files that will drop into the 8953-x folders to a joint folder.
The files that drops to the 8953-x folders will automatically be moved to the joint folder /mnt/FOLDER.
It will move all files besides files containing ! in their filename, for example picture.jpg.!sync.
Files ending with .!sync are in sync between servers, using btsync and not complete, they shall be ignored. When the sync end, the file output will change to picture.jpg, and then I want it to be transferred to the joint folder.
#!/bin/bash
from_folders=(8953-10 8953-11 8953-12 8953-3 8953-4 8953-5 8953-6 8953-7 8953-8 8953-9)
${from_folders[#]}
I believe this should work, but please test on a backup directory.
shopt -s extglob; mv 8953-*/!(\!*) /mnt/FOLDER
This turns on pattern matching and then moves all files in those folders which do not start with exclamation to the destination folder.
If the files all are named .jpg when ready, it is easier:
mv 8953-*/*.jpg /mnt/FOLDER
This is an improved script:
#!/bin/bash
shopt -s extglob
from_folders=(8953-10 8953-11 8953-12 8953-3 8953-4 8953-5 8953-6 8953-7 8953-8 8953-9)
for folder in ${from_folders[#]}
do
echo mv $folder/!(\!*) /mnt/finished_fotograf
done