Is There An App To Both Open And Change File Modification Times For Each File In A Folder?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubuntu 22.04.03 LTS w/ Gnome 42.9 and X11
Posts: 29
Original Poster
Rep:
Quote:
Originally Posted by Racho
If these documents are all the same format and you know a command to read the publication date, you can make a script or a program to update all the timestamps.
We can help you but first let us know some things:
What is the format of these files? Text files, pdf, odt, html....?
what do you exactly mean with "publication date"?
Where in the files can we find the publication date? (metadata, a tag, after some string ...)
The formats might be anything, but are mostly HTML. More specifically, they're mostly downloaded news articles. The publication date is the date you see at the top of most articles, along with the author.
Other file formats are mostly PDF, and in this case the publication date is determined by what's in the PDF. It might be a book with only a year for the date, a report where the publication date might be anywhere or not even included, a government document, etc. All have different text formats and locations for the date, so automating the search for it is out of the question.
I tried writing a software program to do this with HTML files in Visual Studio for Windows. I learned that it's not easy to automate the process of looking for the right date and being sure you get the right one, even just with HTML, so the files have to be viewed manually. That I can accept. But having to use the touch command in bash to edit the file's date requires too much work when dealing with a lot of files, since I would have to look at each HTML file in a browser, then cut/paste the file name and add the proper date in bash for the touch command. Many HTML files have encrypted text, including the date of publication of the article, so that's another problem that has to be considered if you think you can automate this with a script.
A simple date changing utility that works in Gnome's file manager is all I really need. Anyone in this forum for software who suggests using some bash script is off-topic, in my opinion. It won't work anyway. I only mentioned the touch command because that's the only way I currently know how to do it, but it's not really something for bash to handle. It's not even easy to automate with a programming language.
Like I said in my OP, I'll need to open each file in a directory to see the publication dates before changing their modification dates.
The gnome's default file manager has not an option nor an extension to change the file's timestamps. But it has the capability to integrate scripts.
So you either install a file manager that can do that (we suggested filecommander and doublecommander) or make a script for the file manager "files" to cover this feature (help here).
A simple date changing utility that works in Gnome's file manager is all I really need. Anyone in this forum for software who suggests using some bash script is off-topic, in my opinion. It won't work anyway.
Not off topic at all. A right click menu that runs a bash script fits your simple date changing utility requirements. I've expanded it a bit to include a simple date verification and uses current time.
Code:
#!/bin/bash
cfile=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
mtime=$(date '+%H%M')
newdate=$(zenity --entry --title="Change MOD date for file" --text="File to change "$cfile" \n change date YYYY/MM/DD")
if [ $? = 0 ] # check if the user click ok on the zenity form
then
echo "New date =$newdate"
if ! [[ $newdate =~ ^[0-9]{4}/[0-9]{2}/[0-9]{2}$ ]]; then
echo "bad date"
exit
fi
mdate=$(echo $newdate | sed 's;/;;g')
touch -m -t "$mdate$mtime" $cfile
else
echo "Cancel button was pressed"
fi
It's not even easy to automate with a programming language.
Easy is relative - none of the problems you've raised are insurmountable.
Still, if we pretend they are, there's remains a straight-forward solution:
1. Export the file names and modified dates to a tab-separated text file, and open it in suitable software (e.g. LibreOffice Calc)
2. Manually view relevant files and add copy-paste publish dates in a third column, then afterwards ensure each one is accepted as a date and reformatted to a suitable format.
3. Save the result as tab separated file, then write a Bash script to while/read loop through and touch the files.
Distribution: Ubuntu 22.04.03 LTS w/ Gnome 42.9 and X11
Posts: 29
Original Poster
Rep:
Quote:
Originally Posted by boughtonp
Easy is relative - none of the problems you've raised are insurmountable.
Still, if we pretend they are, there's remains a straight-forward solution:
1. Export the file names and modified dates to a tab-separated text file, and open it in suitable software (e.g. LibreOffice Calc)
2. Manually view relevant files and add copy-paste publish dates in a third column, then afterwards ensure each one is accepted as a date and reformatted to a suitable format.
3. Save the result as tab separated file, then write a Bash script to while/read loop through and touch the files.
Do you think that's a straightforward solution? That would require at least as much work as using touch in bash.
I'm trying to minimize the steps needed to perform the task. I posted in the software forum because I thought there might be a software package out there that someone knows about.
Having actual experience in trying to solve a problem is more enlightening than imagining that you can solve it.
f=(*)
for i in "${f[@]}"; do
echo "$i"
sleep 1
done
I have little knowledge of what that's doing and there aren't any comments to explain it, but it looks like overkill on the data it produces and doesn't seem to take into account the fact that I need to look inside each file to get the proper publication date before I can change it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.