Bash script to modify the last modified date using the file name - date

I downloaded all the pictures from an old spanish social network and the Last modified date is the date that I downloaded the file instead of the real date. I would like to order all the pictures by Last modified date to upload to google photos using the correct date.
I know the real date because the image name has the date and time and I would make a script to change de last modified date using the name of the file. I don't care about the time.
Name of the file format: "yyyy-mm-dd hh-mm-ss.jpg"
I'm using windows, but is not a problem to install Unix to execute some bash script, because it may probabbly be easier.
Is there any way to do this?
Thanks in advance

You can use powershell $(Get-Item *Filename*).creationtime=$(Get-Date "mm/dd/yyyy hh:mm am/pm") in a batch file or command prompt to change the creation date of a file. for more information look at this. In your case you could do:
for %%i in (<folder with all the files path>) do (
set name=%%~i
set name=%name:~0,19%
powershell $(Get-Item %%~i).creationtime=$(Get-Date "%name:~5,2%/%name:~8,2%/%name:~0,4% %name:~11,2%:%name:~14,2%")
)
Note: I have not tested this since I do not have the data set for it.

Related

Getting date format from string

I have what I think it's a simple question.
I have a file named like this: 'prec/CHIRPS/P_CHIRPS.v2.0_mm-day-1_daily_2020.01.01.tif' and you can see it has a date within.
I've used successfully the package datefinder to extract the date from that string, but now what I want to do it's actually get the format from which datefinder read that date. That means that I want an output to be '%Y.%m%.d%' so I can use it to write a file with that same date format.
This is for example to be able to use whichever format of date and whichever file name I have, extract both the date and its format, and finally rewrite something like 'this is just an example of the file name with the date 2020.01.01'.
Thanks!!

How to append file's last modification date to file name on moving the file?

I have an Excel add-in for my organization that I regularly update. I have a batch file which moves the previous add-in to an "old" directory, and I want to append the file's last modified date to the file name in order to keep track of all previous versions.
Using %DATE% I can append the current date to the filename, but I want to know how I can append the date for when the file was last modified.
This is my batch file so far, using the %DATE% command.
Ren J:\40_MS\435_Milj›\Annet\Datah†ndtering\Add-ins\435_Milj›.xlam 435_Milj›_old.xlam
Move J:\40_MS\435_Milj›\Annet\Datah†ndtering\Add-ins\435_Milj›_old.xlam J:\40_MS\435_Milj›\Annet\Datah†ndtering\Add-ins\Old\
Ren J:\40_MS\435_Milj›\Annet\Datah†ndtering\Add-ins\Old\435_Milj›_old.xlam 435_Milj›_%DATE%.xlam
Any suggestions are greatly appreciated.
The suggested duplicate doesn't actually explain how to append the file date to the file name. I tried using this script:
Ren C:\Temp\435_Milj›.xlam 435_Milj›_old.xlam
Move C:\Temp\435_Milj›_old.xlam C:\Temp\Old\
for %a in (C:\Temp\Old\435_Milj›_old.xlam) do set MyFileDate=%~ta
Ren C:\Temp\Old\435_Milj›_old 435_Milj›_%MyFileDate%.xlam
But it didn't work. What am I doing wrong?

Add Date and Time stamp to powershell exported file

I am new to scripting but at my work place I see that they are storing warnings, errors and notes from logs of different programs under one file using the below command in a batch file:
check_log.bat > tlglogs
PS: If it matters the different logs and the output tlglogs are in the same Windows folder.
I would like to add a date time stamp to the tlglogs each time I run the batch file. Could you please let me know how to proceed as I am not familiar with scripting? I tried the below via Dr. Google's help but it did not help:
check_log.bat >tlglogs_%Date%
Thanks for your time and help. It is highly appreciated!
Cheers!
In Powershell you can get the current date like below:
Get-Date
You can save it to a variable and also define the format of the returned date.
$d = Get-Date -Format "ddMMyyyy"
So this will return a date in the format like 04082016 and save it in the variable $d which we can use for export.
check_log.bat > "tlglogs_$d"
That should do what you want.
Thanks Junaid, adding the below code in the batch file worked for me:
#echo off
set startDate=%date%
set startTime=%time%
set sdy=%startDate:~10%
set /a sdm=1%startDate:~4,2% - 100
set /a sdd=1%startDate:~7,2% - 100
set /a sth=%startTime:~0,2%
set /a stm=1%startTime:~3,2% - 100
set /a sts=1%startTime:~6,2% - 100
check_log.bat *.log > tlglogs%sdy%.%sdm%.%sdd%-%sth%.%stm%
If there is a much easier way please do let me know. Thanks again!

CMD echo %date% returns '/Tu' instead of a proper date

I am generating the date in a format of YYYYMMDD so that i can append it in the filename that the batch program generates.
But in my local system echo %date% returns
echo %date%
Tue 09/08/2015
The date information is returned so i can modify it the way i want
In server, the same does not return date values
echo %date%
/Tu
I dont have date values to modify it to my required format YYYYMMDD
How do I go about this? Is there any Windows date and time setting that i should be looking at?
The date format depends on the regional settings of your machine. You can check them in control panel (run intl.cpl), they seem to be broken.

powershell get current date format being used by system

How can I use powershell to get the current system date format for example if I was reading a log file using powershell I would like to know if 2012-03-01 is in yyyy-mm-dd or yyyy-dd-mm.
This should give you the DateTime formats for the machine's current culture:
[cultureinfo]::CurrentCulture.DateTimeFormat