Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DOS Batch to set file Last Modified date as another file

Posted on 2011-02-27
11
Medium Priority
?
1,825 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 6

Accepted Solution

by:
dax_bad earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Ok I have been working on this for some time having learned and gained certification in XenDesktop 4 along came version 5 which was released last month. Since then I have been working to deploy XenDesktop 5 in a small environment with only 2 virt…
If you have done a reformat of your hard drive and proceeded to do a successful Windows XP installation, you may notice that a choice between two operating systems when you start up the machine. Here is how to get rid of this: Click Start Clic…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

609 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