64,654
社区成员
发帖
与我相关
我的任务
分享
如果楼主的文件名中的时间格式是定长的话,用正则表达式替换就行了
在UltraEdit中打开"替换"窗口,
在查找中输入:
Perl code^((\d{2})(\d{2})(\d{2})(\d{2}).doc)$
在替换中输入:
Perl codefd /c $1 20$2-$3-$4 $5:00:00
勾上"正则表达式",在点开高级,正则表达式引擎选Perl,最后点全部替换吧.
以上操作描述是针对UltraEdit v14.0版本以上的中文版
Imports System
Imports System.IO
Imports System.Text
Public Class Test
Public Shared Sub Main(ByVal CmdArgs() As String)
Dim ArgNum As Integer ' Index of individual command-line argument.
Dim dt As DateTime
Dim path As String
Dim offset as integer
Dim opt as string
Dim s as string
Dim isGet as boolean
isGet=False
offset=0
opt="/W"
dt=DateTime.Now
If CmdArgs.Length > 0 Then ' See if there are any arguments.
For ArgNum = 0 To CmdArgs.Length-1
if ArgNum=0+offset Then
s=CmdArgs(ArgNum)
if s="/?" then
Console.WriteLine("File or directory Datetime(WAC:lastWrite|lastAccess|Creation)")
Console.WriteLine("Set to Now or YY-MM-DD [hh:mm:ss] or Get")
Console.WriteLine(" FD [/WAC] File_or_Dir_name [[[20]YY-]MM-DD[ hh:mm:ss]]|get")
return
end if
if s.Chars(0)="/" then
opt=s.ToUpper()
if opt.IndexOf("C")=-1 and opt.IndexOf("A")=-1 then
opt=opt+"W"
end if
offset=1
else
path=s
end if
End if
if ArgNum=1+offset Then
s=CmdArgs(ArgNum)
if s.ToUpper()="GET" then
isGet=True
else
Try
dt=DateTime.Parse(s)
Catch e As Exception
Console.WriteLine("Error: Invalid datetime format")
return
End Try
end if
End if
if ArgNum=2+offset Then
Try
dt=DateTime.Parse(CmdArgs(ArgNum-1)+" "+CmdArgs(ArgNum))
Exit for
Catch e As Exception
Console.WriteLine("Error: Invalid datetime format")
return
End Try
End if
Next ArgNum
else
Console.WriteLine("File or directory Datetime(WAC:lastWrite|lastAccess|Creation)")
Console.WriteLine("Set to Now or YY-MM-DD [hh:mm:ss] or Get")
Console.WriteLine(" FD [/WAC] File_or_Dir_name [[[20]YY-]MM-DD[ hh:mm:ss]]|get")
return
End If
Try
If File.Exists(path) = True Then
if opt.IndexOf("W")>-1 then
if isGet then
dt=File.GetLastWriteTime(path)
Console.WriteLine("File Datetime(LastWrite ) of [{0}] is {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
else
File.SetLastWriteTime(path, dt)
Console.WriteLine("File Datetime(LastWrite ) of [{0}] set to {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
end if
end if
if opt.IndexOf("C")>-1 then
if isGet then
dt=File.GetCreationTime(path)
Console.WriteLine("File Datetime(Creation ) of [{0}] is {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
else
File.SetCreationTime(path, dt)
Console.WriteLine("File Datetime(Creation ) of [{0}] set to {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
end if
end if
if opt.IndexOf("A")>-1 then
if isGet then
dt=File.GetLastAccessTime(path)
Console.WriteLine("File Datetime(LastAccess) of [{0}] is {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
else
File.SetLastAccessTime(path, dt)
Console.WriteLine("File Datetime(LastAccess) of [{0}] set to {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
end if
end if
return
end if
Catch e As Exception
Console.WriteLine("Error: {0}", e.ToString())
return
End Try
Try
If File.Exists(path+".lnk") = True Then
if opt.IndexOf("W")>-1 then
if isGet then
dt=File.GetLastWriteTime(path+".lnk")
Console.WriteLine("File Datetime(LastWrite ) of [{0}] is {1}",path+".lnk",dt.ToString("yyyy-MM-dd HH:mm:ss"))
else
File.SetLastWriteTime(path+".lnk", dt)
Console.WriteLine("File Datetime(LastWrite ) of [{0}] set to {1}",path+".lnk",dt.ToString("yyyy-MM-dd HH:mm:ss"))
end if
end if
if opt.IndexOf("C")>-1 then
if isGet then
dt=File.GetCreationTime(path+".lnk")
Console.WriteLine("File Datetime(Creation ) of [{0}] is {1}",path+".lnk",dt.ToString("yyyy-MM-dd HH:mm:ss"))
else
File.SetCreationTime(path+".lnk", dt)
Console.WriteLine("File Datetime(Creation ) of [{0}] set to {1}",path+".lnk",dt.ToString("yyyy-MM-dd HH:mm:ss"))
end if
end if
if opt.IndexOf("A")>-1 then
if isGet then
dt=File.GetLastAccessTime(path+".lnk")
Console.WriteLine("File Datetime(LastAccess) of [{0}] is {1}",path+".lnk",dt.ToString("yyyy-MM-dd HH:mm:ss"))
else
File.SetLastAccessTime(path+".lnk", dt)
Console.WriteLine("File Datetime(LastAccess) of [{0}] set to {1}",path+".lnk",dt.ToString("yyyy-MM-dd HH:mm:ss"))
end if
end if
return
end if
Catch e As Exception
Console.WriteLine("Error: {0}", e.ToString())
return
End Try
Try
If Directory.Exists(path) = True Then
if opt.IndexOf("W")>-1 then
if isGet then
dt=Directory.GetLastWriteTime(path)
Console.WriteLine("Directory Datetime(LastWrite ) of [{0}] is {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
else
Directory.SetLastWriteTime(path, dt)
Console.WriteLine("Directory Datetime(LastWrite ) of [{0}] set to {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
end if
end if
if opt.IndexOf("C")>-1 then
if isGet then
dt=Directory.GetCreationTime(path)
Console.WriteLine("Directory Datetime(Creation ) of [{0}] is {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
else
Directory.SetCreationTime(path, dt)
Console.WriteLine("Directory Datetime(Creation ) of [{0}] set to {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
end if
end if
if opt.IndexOf("A")>-1 then
if isGet then
dt=Directory.GetLastAccessTime(path)
Console.WriteLine("Directory Datetime(LastAccess) of [{0}] is {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
else
Directory.SetLastAccessTime(path, dt)
Console.WriteLine("Directory Datetime(LastAccess) of [{0}] set to {1}",path,dt.ToString("yyyy-MM-dd HH:mm:ss"))
end if
end if
End If
return
Catch e As Exception
Console.WriteLine("Error: {0}", e.ToString())
return
End Try
Console.WriteLine("Error: Can not find File or File.lnk or Dir [{0}]",path)
return
End Sub
End Class