Link to home
Start Free TrialLog in
Avatar of FOX
FOXFlag for United States of America

asked on

Determining copy date

Is there a tool or command to run against files on a usb drive to determine the date they were copied to that drive?
Avatar of Gabriel Clifton
Gabriel Clifton
Flag of United States of America image

Change for your needs

@echo off
setlocal DisableDelayedExpansion
for %%f in (created modified accessed) do if exist %%f.txt del %%f.txt
set "folder=%CD:~2%"
for /F "skip=1 tokens=1-3*" %%a in (
    '"wmic datafile where (path='%folder:\=\\%\\') get InstallDate, LastModified,

LastAccessed, Name"'
                                   ) do (
   for /F "delims=." %%A in ("%%a") do echo %%A %%d>> created.txt
   for /F "delims=." %%B in ("%%b") do echo %%B %%d>> modified.txt
   for /F "delims=." %%C in ("%%c") do echo %%C %%d>> accessed.txt
)

rem Process each list this way:
for /F "tokens=1*" %%a in (created.txt) do echo %%a - %%b
Avatar of FOX

ASKER

for %%f in (created modified accessed) do if exist %%f.txt del %%f.txt - Is f the drive letter of the usb drive in this statement?
no, that would be the variable. you need the line set "folder=%CD:~2%"
Avatar of FOX

ASKER

So if the drive is G the script should look like this? Secondly, do I run this as a batch file or from the command prompt?

@echo off
setlocal DisableDelayedExpansion
for %%f in (created modified accessed) do if exist %%f.txt del %%f.txt
set "G=%CD:~2%"
for /F "skip=1 tokens=1-3*" %%a in (
    '"wmic datafile where (path='G:\=\\%\\') get InstallDate, LastModified,

LastAccessed, Name"'
                                   ) do (
   for /F "delims=." %%A in ("%%a") do echo %%A %%d>> created.txt
   for /F "delims=." %%B in ("%%b") do echo %%B %%d>> modified.txt
   for /F "delims=." %%C in ("%%c") do echo %%C %%d>> accessed.txt
)

rem Process each list this way:
for /F "tokens=1*" %%a in (created.txt) do echo %%a - %%b
set folder=G
Avatar of FOX

ASKER

Please edit the script to show me exactly what it should look like if I have a usb drive G: in my laptop and I want to see the date the files on it were copied to it.  Secondly how am I running the script? As a batch file, do I have to run it in windows shell?, How do I run it?
copy the code into notepad and save as file-dates.bat
to run open the bat file (double click)
@echo off
setlocal DisableDelayedExpansion
for %%f in (created modified accessed) do if exist %%f.txt del %%f.txt
set folder=G
for /F "skip=1 tokens=1-3*" %%a in (
    '"wmic datafile where (path='%folder:\=\\%\\') get InstallDate, LastModified, 

LastAccessed, Name"'
                                   ) do (
   for /F "delims=." %%A in ("%%a") do echo %%A %%d>> created.txt
   for /F "delims=." %%B in ("%%b") do echo %%B %%d>> modified.txt
   for /F "delims=." %%C in ("%%c") do echo %%C %%d>> accessed.txt
)

rem Process each list this way:
for /F "tokens=1*" %%a in (created.txt) do echo %%a - %%b

Open in new window

Avatar of FOX

ASKER

command screen comes up and then disappears...I can see it says cannot find the specified file
Avatar of FOX

ASKER

Is there anything else I need to do to get this running correctly?
Sorry, I have been working on some big projects at work. I will look at the script again when I get back to my office
Avatar of FOX

ASKER

Ok P, I appreciate it.
ASKER CERTIFIED SOLUTION
Avatar of Gabriel Clifton
Gabriel Clifton
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FOX

ASKER

I am using the same exact script you have there. My usb drive is in my laptop as drive F:  I don't have to change anything in the script at all?  I have the same specs as you do.  Win7 x64.  The usb drive has about 1.67gb of data on it.  When I first started the script I saw the light on the usb fluctuating as if something was going on, so I will give it some time.  If there are any results are they going to be piped to the created.txt on the usb drive or on the laptop?
It will go to the directory where it was ran from. you can change that by modifying >>directory\created.txt
Avatar of FOX

ASKER

P, that was it!!!!  I piped the file to location of my choice, not only that, I needed to right-click and run the batch file as administrator.  Thank you!!!!
No problem, glad to help.