2

In SQL Server using xp_cmdshell, I was able to load files according to Modified date using a command for e.g.,

z: & forfiles /m *.jpg /s /d 07/16/2015 /c “cmd /c echo @fdate @ftime @path”

But I wanna know how to load files according to Created date. Any help would be very appreciated.

A question’s been asked on stackoverflow but no answer yet. Please take a look at the link for the details How to load files according to Created Date in Windows command prompt via SQL Server's xp_cmdshell

7
  • i'm not that familiar with forfiles and that line doesn't looks simple, and i'm possibly misunderstanding your question and this may not be relevant but how about dir /? showing dir /t:c which is creation time
    – barlop
    Commented Sep 2, 2015 at 15:11
  • Thanks @barlop, sorry that my question isn't clear enough, actually I want to load all file names with extension ".jpg" including created dates and full directory paths to be stored in a table. An example result should be something like 8/18/2015 11:13:08 AM "Z:\LDB1 App Export\Top Star_Aluminium Frames & Furniture (B)-31267.jpg" Commented Sep 2, 2015 at 17:40
  • I see what you mean. I just tested this for /f "eol=: delims=" %F in ('dir /b /s') do @echo %~ftzaF but it doesn't work. The %tF doesn't show creation time.. even with /t:c on the dir. So i'm not sure.
    – barlop
    Commented Sep 2, 2015 at 18:05
  • if you have a c sharp compiler you could compile this pastebin.com/raw.php?i=6fGPGDBc then it'd run like pastebin.com/raw.php?i=eJV8zYcd so you could use that little program to help on the way to doing what you want... though it's cheating a bit.
    – barlop
    Commented Sep 2, 2015 at 18:28
  • this goes further so it uses that little program for runs it on all txt files you could change txt to jpg pastebin.com/8U0GWP0j So that lists all files and their creation times. You could put that output in a file and do type file | find "02/06/2010" or whatever date you want
    – barlop
    Commented Sep 2, 2015 at 18:34

1 Answer 1

0

This is cheating a little bit, because it involves you compiling a little program that helps do this. It involves a little simple c# program but mostly cmd.

The thinking is, if only cmd included a program/command that when given a filename, it'd give give on one line, the file's full path and creation date/time. Then in cmd one could use a cmd's for command, applying that (show file's path and creation date/time) command to every file. So i've written a little program that can take a filename and show its full path and creation date/time. And then I use it in cmd.

The program..

C:\blah>type a.cs
using System.IO;

class asdf
{

 public static void Main(string[] args) {
    if(args.Length==0) {
         System.Console.WriteLine("Pass a filename");
         return;
     }
    System.IO.FileInfo fileInfo = new FileInfo(args[0]);
    System.Console.Write(fileInfo.FullName+"      ");

     System.DateTime creationTime = fileInfo.CreationTime;
    System.Console.WriteLine("cdt "+creationTime);

     }


}
C:\blah>

Compiling it

C:\blah>csc a.cs
Microsoft (R) Visual C# Compiler version 4.0.30319.18408
for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.


C:\blah>

so that creates a.exe

a.exe is a little program that when passed a filename as a parameter, gives the full path and creation date/time

C:\blah>a.exe w.obj<ENTER>
C:\blah\w.obj      cdt 25/07/2015 1:03:52 AM

C:\blah>

The rest is cmd

If you don't have a C# compiler

I've included a link here to a.cs (the source code above) a.exe and since chrome tries to block any exe, you could download a.ex2 and rename it. Or when Chrome tries to block the exe then say "dismiss" and go to downloads within chrome and say recover file. But however you want to do it, you can get that EXE. Maybe visual studio express (like a free small version of visual studio) will have csc.exe letting you compile it, if you want to do it that way.

http://ge.tt/2LdAiGN2

Once you have that little program then you can do this in cmd

c:\blah>for /r %f in (*.jpg) do @a.exe %f
c:\blah\a.jpg      cdt 31/07/2015 3:55:40 PM
c:\blah\a10.jpg      cdt 3/11/2013 8:19:07 AM
c:\blah\a11.jpg      cdt 3/11/2013 8:19:16 AM
c:\blah\a12.jpg      cdt 3/11/2013 8:48:45 AM
C:\blah\dff\Calendar.jpg      cdt 25/08/2009 3:00:02 AM
C:\blah\dff\CheckDST.jpg      cdt 28/07/2005 2:00:02 AM

So what you can do, is do that command but dumped to a file

C:\blah>del mynewfile.a

C:\blah>for /r %f in (*.jpg) do @a.exe %f >>mynewfile.a

C:\blah>

Then you can use find or gnuwin32's grep

C:\blah>find "22/05/2015" mynewfile.a

---------- MYNEWFILE.A
C:\blah\sdff\a.jpg      cdt 22/05/2015 5:54:53 AM
C:\blah\sdff\a2.jpg      cdt 22/05/2015 6:20:40 AM
C:\blah\sdff\b.jpg      cdt 22/05/2015 5:56:12 AM

or with gnuwin32's grep

C:\blah>grep "22/05/2015" mynewfile.a
C:\blah\sdff\a.jpg      cdt 22/05/2015 5:54:53 AM
C:\blah\sdff\a2.jpg      cdt 22/05/2015 6:20:40 AM
C:\blah\sdff\b.jpg      cdt 22/05/2015 5:56:12 AM

C:\blah>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .