Is It Possible to Auto Change "Date Modified" of One File Using Another File - Page 1
Forum section: electronics / general

author: bostonman
author_rank: Super Contributor
timestamp: April 09, 2025, 01:24:00 pm
content: I wasn't sure how to word the title.I had a couple thousand MP3s with various ones missing the ID3 tags (i.e. no artist and/or song title). Rather than going through individually trying to figure out which ones were missing or making a note on which ones were missing as I played them, I used MP3tag program to take the file name (I try making all file names: artist - song title.mp3) and change the ID3 tag.This worked great, or seemed so, however, in the process, all the 'date modified' times/dates got changed.Although this isn't a major issue, I'd like to have them so I can see when they were obtained.Thankfully I still have a single backup directory with all the same MP3s. They are the originals with wrong ID3 tags but correct date modified so I know when they were obtained.Does a way exist to take all those date modified dates/times and use them to change the modified MP3s with the new ID3 tags since all the file names are the same?

author: Andy Watson
author_rank: Super Contributor
timestamp: April 09, 2025, 01:54:23 pm
content: Depends on your operating system. M$ - don't know. Linux - use touch -d "2004-02-27" MyFile.mp3 This will change the date and times that you normally see, but the node change time will be set to the current time. If you have a file with the desired date/time (the reference file), use touch -r RefFileName.mp3 MyFile.mp3 If you want to program in C, look-up the stat function, I believe it will chage some of the timestamps.

author: bostonman
author_rank: Super Contributor
timestamp: April 09, 2025, 02:13:47 pm
content: QuoteIdeally doing in Windows would be nice, but I can perform it in Linux too. Unfortunately I don't know C programming; or well enough to create such a program.Not sure what the above statement is doing. Will it make all the file dates 2004-02-27 or were you using an example and can this perform a batch change?Keeping the current time isn't a big deal. Ideally in the future it will be nice to see the dates on when I obtained individual songs. If changing them is too much trouble, then leaving them isn't an issue.Sometimes I look at MP3s I got in the early 2000s and try connecting the date with an event; or it will remind me how I obtained a particular song. Other times I'll see a time and think: what the heck was I doing up that late.These are reasons having the correct date/time on when they were obtained is nice.

author: Andy Watson
author_rank: Super Contributor
timestamp: April 09, 2025, 02:49:39 pm
content: Quote from: bostonman on April 09, 2025, 02:13:47 pmSorry, I don't trespass thereQuoteThat was an example (pulled from the help information.) If you want a batch change you could write a script file.I think you want the second form that I gave, i.e. touch -r this.mp3 that mp3. This will copy the details from this.mp3 to that.mp3, however, it only works one reference file at a time. I've jsut tried using wildcards and it copies the details of the first file in the list to all the other files.

author: bostonman
author_rank: Super Contributor
timestamp: April 09, 2025, 09:47:37 pm
content: QuoteI haven't tried it, but downloaded it.Browsing through, it seems like it's a great solution.

author: Nominal Animal
author_rank: Super Contributor
timestamp: April 10, 2025, 03:19:29 am
content: In Linux:Change (cd) to the directory with the active files. Let's say the corresponding backup or reference file tree is at/media/me/backup/mp3s/. Runfind . -iname '*.mp3' -exec touch -c -r '/media/me/backup/mp3s/{}' '{}' ';'and you're done. This assumes the file and directory names match, and runstouch -c -rbackuppath/path/filepath/filefor each file ending with.mp3(in uppercase or lowercase or mixed) in the current directory or any of its subdirectories at any depth. The-coption tells touch not to create any new files, and-rreferencefileoption specifies the file that the timestamps are taken from.If the directory trees do not match, you can limit the operation to the current directory by usingfind . -maxdepth 1 -iname '*.mp3' -exec touch -c -r '/media/me/backup/mp3s/{}' '{}' ';'For further details, seeman 1 findandman 1 touchman pages.

author: bostonman
author_rank: Super Contributor
timestamp: April 10, 2025, 12:12:34 pm
content: Type it that way with the apostrophes too?I was messing around with the script file that was linked in a previous post, but was having difficulty.

author: Nominal Animal
author_rank: Super Contributor
timestamp: April 10, 2025, 01:45:06 pm
content: Quote from: bostonman on April 10, 2025, 12:12:34 pmYes. They're single quotes, not apostrophes, syntactically.The difference between double quotes and single quotes in bash/dash/ash/sh is that single quoted strings are used as-is, whereas double quoted strings will have variable substitution applied first.If you just want to see what commands would get run, usefind . -iname '*.mp3' -execechotouch -c -r '/media/me/backup/mp3s/{}' '{}' ';'

author: ramussons
author_rank: Contributor
timestamp: April 12, 2025, 12:35:49 pm
content: Why not look atBulkFileChanger v1.71Copyright (c) 2010 - 2020 Nir SoferWeb site:http://www.nirsoft.netI have used it for a lot of changes, but the manual says you can tranfer the dates from one file to another.".... to create files listfrom multiple folders, and then make some action on them - Modify theircreated/modified/accessed time, change their file attribute (Read Only,Hidden, System), run an executable with these files as parameter,..."I have not used this option.

author: bostonman
author_rank: Super Contributor
timestamp: April 15, 2025, 01:10:23 am
content: QuoteNot sure if I did something wrong, but I did a test run.You stated those are not apostrophes but a single quote. Am I not seeing something on my keyboard other than apostrophes?I have my MP3s in (using your example) /media/me/backup/mp3s/ and the correct ones in /media/me/backup/mp3s/good, but I don't understand the command format, so I can't figure out where the error(s) are.It seemed to just freeze when I typed the above command.

author: sleemanj
author_rank: Super Contributor
timestamp: April 15, 2025, 02:37:32 am
content: Asked gemini, quick skim looks like it might workhttps://g.co/gemini/share/863583e498fbHere is the code it wrote directly, set the src and dst paths as appropriate and I would change the "touch" line to put "echo" in front of it for testing and see if it makes sense, if it does, change it back and there you go.Code:#!/bin/bash# Source directory where the original MP3 files are located.src_dir="src"# Destination directory where the MP3 files need to have their modification times updated.dst_dir="dst"# Check if the source directory exists.if [ ! -d "$src_dir" ]; thenecho "Error: Source directory '$src_dir' does not exist."exit 1fi# Check if the destination directory exists.if [ ! -d "$dst_dir" ]; thenecho "Error: Destination directory '$dst_dir' does not exist."exit 1fi# Find all MP3 files in the source directory and process them.find "$src_dir" -name "*.mp3" -print0 | while IFS= read -r -d $'\0' src_file; do# Get the relative path of the MP3 file from the source directory.relative_path=$(echo "$src_file" | sed "s|^$src_dir/||")# Construct the corresponding destination file path.dst_file="$dst_dir/$relative_path"# Check if the destination file exists.if [ -f "$dst_file" ]; then# Update the modification time of the destination file to match the source file.touch -r "$src_file" "$dst_file"echo "Updated modification time of '$dst_file' to match '$src_file'."elseecho "Warning: Destination file '$dst_file' does not exist. Skipping."fidoneecho "Finished processing MP3 files."exit 0

author: Nominal Animal
author_rank: Super Contributor
timestamp: April 15, 2025, 10:09:49 am
content: Quote from: bostonman on April 15, 2025, 01:10:23 amSyntactically, yes. An apostrophe is a punctuation mark, whereas single quotes are always in pairs. The character is the same, but the use is completely different.The difference is the same as when trying to teach someone read English. You could say each word is an ideogram, and they just need to learn to identify each word and what they mean. Or, you can say each word consists of letters, transformed to phonemes using some very weird rules, but just a few rules can get you very close and understandable. One can learn to read English either way, but only one of them makes practical sense.Quote from: bostonman on April 15, 2025, 01:10:23 amThe command works best when the backups and the active files are in separate directory trees, say/media/me/backupand/home/me/Music. Then, you usecd /home/me/Musicfind . -iname '*.mp3' -exec touch -c -r '/media/me/backup/{}' '{}' ';'findis the command name..specifies the directory where the file search starts, and refers to current working directory.-iname '*.mp3'sets the search criterion to name ending with.mp3ignoring case.-exec ... ';'tells find to execute a command for each matching file or directory name. In the ellipsis part, any occurrence of{}is replaced with matching name, including relative path if in a subdirectory.touchis the command name.-coption tells touch to not create a new file if the target file does not exist.-rpathtells touch to update the target file timestamps based on those ofpath.'{}'specifies the target file whose timestamps will be modified; this is the path to the file found by find.Here, we use/media/me/backup/targetas the reference for the timestamps, copying those timestamps to./target.We use single quotes,'...', so that file names with spaces and such will be handled correctly. The command has four such quoted strings, and therefore exactly eight'characters. If you think of those characters as apostrophes, you easily accidentally omit one, causing the shell to wait for the rest of the command. This is why it is important to remember they are single quotes and always in pairs, and not some random punctuation that you drop here and there.We could use double quotes,"...", but then shell would expand any variable references and special characters, which we do not want. We want to use single quotes, because that way the string inside the single quotes is used as-is, without interpretation.If you want find to print the target file as it finds them, usecd /home/me/Musicfind . -iname '*.mp3' -print -exec touch -c -r '/media/me/backup/{}' '{}' ';'Let's say you have a slightly different case: the music files are in/home/me/Music/, and the backups in a subdirectory,/home/me/Music/backup/.If we run the above command, it will go through all files twice. It will work, just take much longer than is necessary, at least half of the commands not doing anything. To save time, we find each backup file instead, and name the corresponding active target file whose timestamps need to be updated:cd /home/me/Music/backupfind . -iname '*.mp3' -exec touch -c -r '{}' '/home/me/Music/{}' ';'This time, we use find to find each backup file, so we tell touch to use that backup file as the reference, and the full path to the corresponding active mp3 file as the target. Again, the single quotes are paired, and as there are four single-quoted strings, you have exactly eight'characters.