Solved

DOS Batch to set file Last Modified date as another file

Posted on 2011-02-27
11
1,817 Views
Last Modified: 2012-06-22
In my work I take many video files as records using digital camera. Then I convert them to MP4 to save space, then I will delete the original MOV files. However, all video converters I've tried lack the ability to keep the output files' Last Modified Date as the original input files'.

I've tried many different programs (SetFileDate, FileDate etc.) but they all set file date to a particular or relative date/time, not using the date from another file. (The Linux TOUCH tool seems able to do this, but the Windows versions lack this function)

In my scenario, after conversion, the original and output video files are typically of same file name and in same folder, but have different extension::
CIMG0001.MOV (original)
CIMG0001.MP4 (output)
CIMG0002.MOV (original)
CIMG0002.MP4 (output)
etc.

Is there a way to scan all the MP4 files in a folder and copy the Last Modified Date from the corresponding (i.e. same filename, different extension) MOV?
I prefer a command line batch solution so that I can modify in future, but VBScript is also ok.
I use WinXP and Win7.

Thanks
0
Comment
Question by:alexkfl
  • 6
  • 5
11 Comments
 
LVL 6

Accepted Solution

by:
dax_bad earned 500 total points
ID: 34995814
Hi Alexkfl,

I can't help with a DOS batch script, but i wrote this small vbscript that can do this for you.

All you need to do is edit the source  folder path, the .mov and .mp4 files must be in the same source folder(not in subfolders).

Let me know if it works the way you want.

Cheers
Daniel
folder = "C:\Test\somefolder" 'Enter the folder where your .mov and .mp4 files are located (must be the same directory)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(folder)
Set objRE = new RegExp
objRE.IgnoreCase = True

Set objApp = CreateObject("Shell.Application") 
Set objAppFolder = objApp.NameSpace(folder) 

For Each objMovFile In objFolder.Files 
	If Right(objMovFile.Name,4) = ".mov" Then
		OldVAlue = objMovFile.DateLastModified
		objRE.Pattern = Left(objMovFile.Name,Len(objMovFile.Name)-4)
		For Each objMp4File In objFolder.Files
			If objRE.Test(objMp4File.Name) Then
				If Right(objMp4File.Name,4) = ".mp4" Then
					Set Appfile = objAppFolder.ParseName(objMp4File.Name)
					Appfile.ModifyDate = OldVAlue
					Set AppFile = Nothing
					Exit for
				End if
			End If
		Next
	End if
Next

Set objFSO = Nothing
Set objFolder = Nothing
Set objFiles = Nothing
WScript.Quit

Open in new window

0
 

Author Comment

by:alexkfl
ID: 34996226
Hi dax_bad:

Thanks for your quick reply.
Unfortunately when I used the script, nothing happens.

I put the *.MOV and *.MP4 in the same folder (D:\Test) and then I edit the "folder =" line to
folder = "D:\Test", and when I run the VBS (by double click or "cscript test.vbs", there is a flash of a command window. But the MP4 files' date are not changed.

I am not familiar with VBscript. Am I missing anything?
Also, I am in Hong Kong and use the date format "dd/mm/yyyy hh:mm", does it matter?



0
 
LVL 6

Expert Comment

by:dax_bad
ID: 34996270
hmm worked fine when i tested it. I had the actual script file in the same folder as well though. It doesnt matter what format you use, it uses the dateModified filed on the file attributes. You're running win7 right? Try to start the cmd prompt with adminstrator permission also make sure the account you run it from has local admin permissions on the file. the .mov and .mp4 files have identical names right?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Closing Comment

by:alexkfl
ID: 34996339
It didn't work in my first trial.
Turns out that the file extenstion are case-sensitive. (My MOV and MP4 files have uppercase file extensions).
 
I changed the ".mov" and ".mp4" in the script to ".MOV" and ".MP4" and it worked like a charm.

Thanks.
That will save me a lot of time.
0
 
LVL 6

Expert Comment

by:dax_bad
ID: 34996472
Ahh right, i can rewrite it to use regular expressions for the file extentions to make it non case sensitive if you want?

glad you got it working

Cheers
Daniel
0
 

Author Comment

by:alexkfl
ID: 35003719
Yes, that would be even better.
Thanks
0
 

Author Comment

by:alexkfl
ID: 35004027
Also, is it possible to set the folder path to current directory, so that I can just COPY the VBS file to the video folder and run from there, to save me having to edit it when I use another folder?

I've tried with blank path ("") and ".", but didn't work.
0
 
LVL 6

Expert Comment

by:dax_bad
ID: 35004734
give me a bit
0
 
LVL 6

Expert Comment

by:dax_bad
ID: 35005679
Hi again alexfl,

I've Updated the script to fit your wishes.

But as you already accepted the first code, this better working version will not be listed as a solution, which i think it should be although the above is also correct. So question is if we should create a new question to update the script as i also spent an hour updating and testing the script, so would appriciate the points. What do you think? :-)

If you agree post the new Q URL here and ill upload the script. If not, let me knwo and ill add it to this one.

Cheers
Daniel
0
 
LVL 6

Expert Comment

by:dax_bad
ID: 35005688
Use the "Ask a related question" above the Add your comment box and please add vbscript as a zone ass well.
0
 

Author Comment

by:alexkfl
ID: 35014345
OK, I'll ask a related question, but I am quite new to EE, so not sure how to do it. I'll try.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Screen Mirroring 7 92
What is this Task? 4 151
How do I search an FTP site for a specific file name/pattern? 3 66
how to diff two files 12 42
Can you find a fax from a vendor you saved a decade ago in seconds? Have you ever cursed your PC under your breath during an audit because you couldn’t find the requested statement or driver history?  If you answered no to the first question or yes …
cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question