Batch file to output filename to csv file
Solved/Closed
CP1717
-
Dec 9, 2008 at 02:59 PM
Richard.Williams Posts 25 Registration date Saturday November 7, 2009 Status Member Last seen July 18, 2012 - Dec 30, 2009 at 12:12 PM
Richard.Williams Posts 25 Registration date Saturday November 7, 2009 Status Member Last seen July 18, 2012 - Dec 30, 2009 at 12:12 PM
Related:
- Batch file output to csv
- Windows 10 iso file download 64-bit - Download - Windows
- Ping batch file output to text - Guide
- Kmspico zip file download - Download - Other
- Could not create output file delphi - Guide
- How to send audio file on instagram ✓ - Instagram Forum
4 responses
Swarve
Posts
4
Registration date
Monday December 8, 2008
Status
Member
Last seen
December 10, 2008
4
Dec 9, 2008 at 05:37 PM
Dec 9, 2008 at 05:37 PM
Hi CP1717,
The script you need is as follows:
____________________Begin Code__________________
Dim Filepath
Dim Filename
Dim OutputFile
Filepath = "c:\test\" 'Edit this to specify the filepath
Filename = "file1.csv" 'Name of file that last edited date/time is needed
OutputFile = "file2.csv" 'File to output results to
Set objFSO = CreateObject("Scripting.FileSystemObject")
If not objFSO.FileExists(FilePath & OutputFile) then
Set objFile = objFSO.CreateTextFile(Filepath & OutputFile)
Wscript.sleep(2000) 'Pause while file is being created
End If
If objFSO.FileExists(Filepath & Filename) then
Set objFile = objFSO.GetFile(Filepath & Filename)
Lastmodifieddate = objFile.DateLastModified
Const ForWriting = 2
Set outputFile = objFSO.OpenTextFile(Filepath & "file2.csv", ForWriting) ' Open file for writing
OutputFile.Write Filename & "," & objFile.DateLastModified 'Write filename and last modified date to output file
OutputFile.Close
End If
set objFSO = Nothing
____________________End Code__________________
The three variables, filepath, filename and output file that are set up on lines 5, 6 and 7 can be modified to pick up any path and filename that you specify and will create the file on line 7 on the same path.
If you save that code as test.vbs file, then in your batch file, you will need to enter the line "Call test.vbs". Obviously if you change the name of the vbs file, you will need to change the reference to it in your batch file.
Bandy (now known as Swarve since I've joined)
The script you need is as follows:
____________________Begin Code__________________
Dim Filepath
Dim Filename
Dim OutputFile
Filepath = "c:\test\" 'Edit this to specify the filepath
Filename = "file1.csv" 'Name of file that last edited date/time is needed
OutputFile = "file2.csv" 'File to output results to
Set objFSO = CreateObject("Scripting.FileSystemObject")
If not objFSO.FileExists(FilePath & OutputFile) then
Set objFile = objFSO.CreateTextFile(Filepath & OutputFile)
Wscript.sleep(2000) 'Pause while file is being created
End If
If objFSO.FileExists(Filepath & Filename) then
Set objFile = objFSO.GetFile(Filepath & Filename)
Lastmodifieddate = objFile.DateLastModified
Const ForWriting = 2
Set outputFile = objFSO.OpenTextFile(Filepath & "file2.csv", ForWriting) ' Open file for writing
OutputFile.Write Filename & "," & objFile.DateLastModified 'Write filename and last modified date to output file
OutputFile.Close
End If
set objFSO = Nothing
____________________End Code__________________
The three variables, filepath, filename and output file that are set up on lines 5, 6 and 7 can be modified to pick up any path and filename that you specify and will create the file on line 7 on the same path.
If you save that code as test.vbs file, then in your batch file, you will need to enter the line "Call test.vbs". Obviously if you change the name of the vbs file, you will need to change the reference to it in your batch file.
Bandy (now known as Swarve since I've joined)
Dec 9, 2008 at 05:47 PM
Thanks so much! I can figure it out from here. You are my hero!
Dec 9, 2008 at 05:55 PM
If you want to find out more about vb scripting, here are a couple of good starting points:
http://www.w3schools.com/Vbscript/default.asp
https://docs.microsoft.com/en-us/?mfr=true
Cheers,
Swarve
Feb 24, 2009 at 02:58 AM
How can make a vbs file is it the same as creating a batch file? I wanna know how to make my html file change it extension name to .txt files with date included.
example:
ren *.html -> 02-20-2009 *.txt
Please and Thank you.