VB Script & BAT : identify who has modify a file

Hello experts,

I was wondering how can I identify who has done the last modification in a file.
The idea is to have a script which checks all the files in a RefFolder and output a log-files composed by the following information:
File1.xls last modification done by """" at ""
File2xls last modification done by "" at """"


Thank you in advance for your help.
LVL 1
LD16Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
Make a .bat of this:
@echo off
setlocal
set fn=*.*

for /f "tokens=1-6" %%a in ('dir /q "%fn%"') do (
   if /i "%%f" neq "" (
      if /i "%%f" neq "no" echo "%%f" last modification done by "%%e" at "%%a %%b %%c"
   )
)

Open in new window

0
LD16Author Commented:
@NewVillageIT: if I want to specify an specific variable for the folder and a log-file.txt to write the last modification done by? How can I do it this?
0
NVITEnd-user supportCommented:
@echo off
setlocal
set FNPatt=*.*
set FNLog=%userprofile%\documents\log-file.txt

for /f "tokens=1-6" %%a in ('dir /q "%FNPatt%"') do (
   if /i "%%f" neq "" (
      if /i "%%f" neq "no" echo "%%f" last modification done by "%%e" at "%%a %%b %%c">>"%FNLog%"
   )
)

Open in new window

0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Bill PrewIT / Software Engineering ConsultantCommented:
Windows doesn't normally store the user that last modified a file.  If you enable object access logging then you can extract that from the security event log.  But that has to be set up on each machine desired.

Are you just interested in XLS files, there may be another option if so.

~bp
0
LD16Author Commented:
@Bill: thank you for your feedback, I am just interesting in xls and if possible in csv, however if there a reliable way just for xls I am in.
0
Bill PrewIT / Software Engineering ConsultantCommented:
Give this a try:

' Text file I/O constants
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

'Create the file system object for creating folders:
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Create Excel application
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False

' Define folders and files to work with
strBaseDir = "B:\EE\EE28630453\Files"
strLogFile = objFSO.GetAbsolutePathName(".") & "\modify-log.txt"
strFileFilter = ".xls"

' Make sure input folder exist
If Not objFSO.FolderExists(strBaseDir) Then
   Wscript.Echo Now & " ERROR: Input folder """ & strBaseDir & """ does not exist."
   Wscript.Quit
End If

' Open log file for appending
Set objLog = objFSO.OpenTextFile(strLogFile, ForWriting, True)

' Process all files in folder
For Each objFile In objFSO.GetFolder(strBaseDir).Files

   ' Make sure it matches the files we want to copy
   If LCase(Right(objFile.Name, Len(strFileFilter))) = LCase(strFileFilter) Then

      ' Load the file into excel
      Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)

      ' Gather desired Office metadata (https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.builtindocumentproperties.aspx)
      strLastSaveTime = objWorkbook.BuiltinDocumentProperties("Last Save Time")
      strLastAuthor = objWorkbook.BuiltinDocumentProperties("Last Author")

      ' Close this file in excel
      objWorkbook.Close False
      Set objWorkbook = Nothing

      ' Log info for this file
      objLog.WriteLine """" & objFile.Name & """ last modification done by """ & strLastAuthor & """ at """ & strLastSaveTime & """"

   End If

Next

' Wrap up
objLog.Close
objExcel.Quit

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LD16Author Commented:
Great, it works! Thank you!
0
Bill PrewIT / Software Engineering ConsultantCommented:
Welcome.

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.