|
Ein Programm in der Programmiersprache | A program in the programming language | |||
Visual BASIC 2015 | ||||
Code für das Setzen von Datum und Uhrzeit einer Datei auf der Festplatte | Code for Setting of Date and Time of a File on Disk | |||
In vbScript kann Datum und Uhrzeit von Dateien nur mittels eines Programms "FileTouch.exe" verändert
werden, das aus dem Internet herunter geladen werden und per Programm aufgerufen muss.
Diese Methode ist hier gezeigt unter Verwendung von VB 2015-Code, aber VB 2015 benötigt das FileTouch
nicht und man erspart dabei eine Menge Code.
Beide Methoden sind hier gezeigt.
|
In vbScript Date and Clocktime can only be changed my means of a program "FileTouch.exe", which must be
downloaded from internet and called by the program. This method is shown here by use of VB 2015-code,
but VB 2015 does not need this FileTouch and one saves a lot of code.
Both Methods are shown here.
| |||
Beschreibung in Arbeit Das Programm ist getestet vor der Publikation, aber es kann keine Garantie gegeben werden, dass es fehlerfrei ist | Description in the works The program ist tested before publication, but there can be given no guarantee, that it is free of errors | |||
11. Mai 2016 | May 11th 2016 |
Program-Code' Code in Visual BASIC 2015Public Class Form1 Private PGM As New Program Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Main() End Sub End Class Public Class Program Sub Main() Dim fSpec = "YourFileSpec (c:\...)" MsgBox(SetFileTime(fSpec)) ' displays True or False MsgBox(GetFileTime(fSpec)) ' displays "dd.mm.yyyy hh:mm:ss" End Sub End Class Imports System.IO Public Module GeneralUsedProcedures Private Version = "without FileTouch" Public WorkPath = "YourPath" Public FileTouchSpec = BPth(WorkPath, "FileTouch.exe") ' FileTouch.exe to download from internet ' 2 versions, one by use of FileTouch, one without Public Function SetFileTimeWithFileTouch(xfSpec) As Boolean ' now = "dd.mm.yyyy hh:mm:ss" If Not FiE(xfSpec) Then Return False Dim MyFile As New FileInfo(xfSpec) If version = "without FileTouch" Then Dim MyFile As New FileInfo(xfSpec) MyFile.LastWriteTime() = Now ' now = "dd.mm.yyyy hh:mm:ss" Return True ElseIf Version = "with FileTouch" Then ' CmdLine = "/D mm-dd-yyyy /T hh:mm:ss filename.ext" If Not FiE(FileTouchSpec) Then Return False Dim SetTime = Now.ToString, DT = Split(SetTime, " "), D = Split(DT(0), ".") SWAP(D(0), D(1)) : DT(0) = String.Join("-", D) ' DT(0) = mm-dd-yyyy Dim CmdLine = String.Join(" ", {"/D", DT(0), "/T", DT(1), ""}) & qo(xfSpec) Process.Start(FileTouchSpec, CmdLine).WaitForExit() If GetFileTime(xfSpec) = SetTime Then Return True Else Return False ' returns True if Date and Time correct after setting End If End Function Public Function GetFileTime(xfSpec) As String 'returns format: "dd.mm.yyyy hh:mm:ss" If Not FiE(xfSpec) Then Return "" Dim MyFile As New FileInfo(xfSpec), Version = "without FileTouch" If version = "without FileTouch" Then Return MyFile.LastWriteTime() ' "dd.mm.yyyy hh:mm:ss" ElseIf Version = "with FileTouch" then Return My.Computer.FileSystem.GetFileInfo(xfSpec).LastWriteTime.ToString End If End Function Public Function FiE(xfSpec) As Boolean ' File Exists If xfSpec = "" Then Return False Return My.Computer.FileSystem.FileExists(xfSpec) End Function Public Function BPth(xPath, xFile) As String Return IO.Path.Combine(xPath, xFile) End Function ' needed for use of FileTouch Public Sub SWAP(ByRef xVar1, ByRef xVar2) Dim vTmp : vTmp = xVar1 : xVar1 = xVar2 : xVar2 = vTmp End Sub Public Function qo(xStr) As String Return """" & xStr & """" End Function End Module How to use FileTouch.exe | ||