Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CODE TO CHANGE ALL FILENAMES TO DATE AND TIME
#2
much simpler is to format the filename with timeformat
Code:
Copy      Help
int i
ARRAY(str) a
GetFilesInFolder a "$Desktop$\TEST\" ""
a.sort(8)
for i 0 a.len
,Dir d.dir(a[i])
,if(d.FileSize > 0);;error handing to make sure file is not empty(if we try to access empty file, the function will error and end)
,,;;out d.FileName
,,str R=CsFunc("" d.FullPath)
,,if(R !="No MetaData Found")
,,,DateTime dt
,,,dt.FromStr(R)
,,,_s.timeformat("C:\Users\emers\Desktop\TEST\{yyyy-MM-dd}__{HH-mm-ss}.jpg" dt)
,,,out _s
,,,ren a[i] _s
,,else
,,,out R
#ret
using System;
using System.Drawing.Imaging;
using System.Drawing;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
public class Example
{
,private static Regex r = new Regex(":");
;;;;//retrieves the date taken without loading the whole image
,public static string GetDateTakenFromImage(string path)
,{
,,using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
,,using (Image myImage = Image.FromStream(fs, false, false))
,,{
,,,PropertyItem propItem = null;
,,,try
,,,{
,,,,propItem = myImage.GetPropertyItem(0x9003);
,,,}
,,,catch { }
,,,if (propItem != null)
,,,{
,,,,string dateTaken = r.Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2);
,,,,return dateTaken;
,,,}
,,,else
,,,,return "No MetaData Found";
,,}
,}
}


Messages In This Thread
RE: CODE TO CHANGE ALL FILENAMES TO DATE AND TIME - by Kevin - 08-16-2019, 06:00 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)