Solved

DOS Batch to set file Last Modified date as another file

Posted on 2011-02-27
11
1,805 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now