如何批量修改文件创建时间?

endfly 2010-01-26 10:05:56
比如我有文件名为10012623.doc的文件意思是10年1月26号23点生成的文件,我想把文件的创建时间就改成这个时间,如何来操作?最好用C,C++或C#来实现。要求是批量修改,因为有大量的文件。谢谢
...全文
7059 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
码农玩抖音 2012-06-13
  • 打赏
  • 举报
回复
【功能】:批量修改指定目录下的所有文件和文件夹的时间属性

创建时间属性的修改、最后修改时间属性的修改、最后访问时间属性的修改

【使用】:①在第一个文本框里面输入路径,如C:\test ②在日期上单击,选择日期。 ③点击批量修改。

【说明】:有些时候文件的时间属性很重要,为了网站文件的统一管理、或者为了隐藏某些秘密,反正你懂的!

http://down.chinaz.com/soft/32578.htm
endfly 2011-12-23
  • 打赏
  • 举报
回复
看看帖子,就能用了。
kensou84 2011-11-07
  • 打赏
  • 举报
回复
我也想用
endfly 2010-02-07
  • 打赏
  • 举报
回复
谢谢各位了,结贴,问题解决,列模块修改的方法是
如果楼主的文件名中的时间格式是定长的话,用正则表达式替换就行了 

在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版本以上的中文版

此方法是“theone11”提供,非常感谢
文件修改函数是zhao4zhong1提供。还有批处理方法也是这位大哥提供,谢谢你们啊,我是搞web的。对这方面就是一菜鸟,谢谢各位,结贴!
另外:/c, /w ,/a,是三个参数,一个修改创建时间,一个修改最后修改时间,/A没看,就剩下最后一个时间了,就不用看了。最后就是批处理和程序要和准备修改的文件放在一起
endfly 2010-02-07
  • 打赏
  • 举报
回复
看了下代码:估计是/w或者/A了
endfly 2010-02-07
  • 打赏
  • 举报
回复
已经搞定,是文件的属性设置为了只读,批处理和程序只能放在要修改的文件的同一目录下,还有就是此修改之修改了文件的创建时间,修改时间怎么改啊?
yzx714 2010-02-07
  • 打赏
  • 举报
回复
NB!VB都上了,谁还来整出个易语言的啊~
endfly 2010-02-07
  • 打赏
  • 举报
回复
是这样的我将批处理文件和fd.exe执行文件与要修改的文件放在一起执行 fd c:/his 10010913.doc 2010-01-09 13:00:00的时候,会提示:对路径c:/his/10010913.doc的访问被拒绝。所以我把批处理和fd.exe放到了要修改的文件的外面,就是要修改的文件在c:/his文件夹里,批处理和程序在c:/根目录下,但这会执行fd /c 10010913.doc 2010-01-09 13:00:00就提示时间格式不正确。不知道为什么啊。
endfly 2010-02-07
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 theone11 的回复:]
楼主试试运行 fd /c 10010913.doc "2010-01-09 13:00:00"看看会不会报错
[/Quote]

不行啊,还是提示时间格式不正确
theone11 2010-02-07
  • 打赏
  • 举报
回复
楼主试试运行 fd /c 10010913.doc "2010-01-09 13:00:00"看看会不会报错
endfly 2010-02-07
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 zhao4zhong1 的回复:]
引用 12 楼 endfly 的回复:
是根据时间类型的文件名来自动读取文件名所代表的时间为修改时间吗?
好好看看问题的内容

将我的程序编译成执行文件fd.exe
然后
·在cmd窗口里面执行“dir /b *.doc >fct.bat”命令将所有.doc文件的文件名生成到文件fct.bat中
·用UltraEdit的列块编辑功能将
10012623.doc
10012723.doc
……
10013023.doc
编辑修改为
fd /c 10012623.doc 2010-01-26 23:00:00
fd /c 10012723.doc 2010-01-27 23:00:00
……
fd /c 10013023.doc 2010-01-30 23:00:00
保存退出
·运行fct.bat

这样难道不能解决楼主的问题吗?

[/Quote]
已经改成这个格式了,程序用的你提供的那个下载,下载的,但是报错,
fd /c 10010913.doc 2010-01-09 13:00:00
fd /c 10010914.doc 2010-01-09 14:00:00
fd /c 10010915.doc 2010-01-09 15:00:00
fd /c 10010916.doc 2010-01-09 16:00:00
fd /c 10010917.doc 2010-01-09 17:00:00
报错信息:
C:\>fd c/hisdat 10010921.doc 2010-01-09 21:00:00
Error: Invalid datetime format

C:\>fd c/hisdat 10010922.doc 2010-01-09 22:00:00
Error: Invalid datetime format

C:\>fd c/hisdat 10010923.doc 2010-01-09 23:00:00
Error: Invalid datetime format
看了下你上面的程序,应该是时间格式不对,但是 dt=DateTime.Parse(s)里面时间的格式应该就是2010-01-09 23:00:00。帮忙看下啊。
endfly 2010-02-06
  • 打赏
  • 举报
回复
顶起来
endfly 2010-02-05
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 zhao4zhong1 的回复:]
引用 12 楼 endfly 的回复:
是根据时间类型的文件名来自动读取文件名所代表的时间为修改时间吗?
好好看看问题的内容

将我的程序编译成执行文件fd.exe
然后
·在cmd窗口里面执行“dir /b *.doc >fct.bat”命令将所有.doc文件的文件名生成到文件fct.bat中
·用UltraEdit的列块编辑功能将
10012623.doc
10012723.doc
……
10013023.doc
编辑修改为
fd /c 10012623.doc 2010-01-26 23:00:00
fd /c 10012723.doc 2010-01-27 23:00:00
……
fd /c 10013023.doc 2010-01-30 23:00:00
保存退出
·运行fct.bat

这样难道不能解决楼主的问题吗?

[/Quote]

实在不好意思啊。问个问题·用UltraEdit的列块编辑功能修改那个,怎么修改啊?应该是正则表达式吧,我没用过UltraEdit。看了一下,自己解决不了,能告诉一下嘛?
赵4老师 2010-02-02
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 endfly 的回复:]
是根据时间类型的文件名来自动读取文件名所代表的时间为修改时间吗?
好好看看问题的内容
[/Quote]
将我的程序编译成执行文件fd.exe
然后
·在cmd窗口里面执行“dir /b *.doc >fct.bat”命令将所有.doc文件的文件名生成到文件fct.bat中
·用UltraEdit的列块编辑功能将
10012623.doc
10012723.doc
……
10013023.doc
编辑修改为
fd /c 10012623.doc 2010-01-26 23:00:00
fd /c 10012723.doc 2010-01-27 23:00:00
……
fd /c 10013023.doc 2010-01-30 23:00:00
保存退出
·运行fct.bat

这样难道不能解决楼主的问题吗?
shiweifu 2010-02-01
  • 打赏
  • 举报
回复
在Win2K以后我使用CreateFile和SetFileTime可以修改文件/文件夹的时间
详情请看:
http://www.cnsdn.com.cn/inc/show.asp?id=4294

写的很全面。。
给分吧
jackzhhuang 2010-02-01
  • 打赏
  • 举报
回复
好像有,你看看msdn的文件专题。

在驱动层可以修改,但我想没必要小题大作吧。
endfly 2010-02-01
  • 打赏
  • 举报
回复
有没有解决办法啊?
endfly 2010-01-31
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zhao4zhong1 的回复:]
到我的资源http://download.csdn.net/zhao4zhong1里面下载“修改文件或文件夹日期时间的命令行工具”这里特给出源码
VB.NET codeImports SystemImports System.IOImports System.TextPublicClass TestPublicSharedSub Main(ByVal CmdArgs()AsString)Dim ArgNumAsInteger' Index of individual command-line argument.Dim dtAs DateTimeDim pathAsStringDim offsetasintegerDim optasstringDim sasstringDim isGetasboolean
isGet=False
offset=0
opt="/W"
dt=DateTime.NowIf CmdArgs.Length>0Then' See if there are any arguments.For ArgNum=0To CmdArgs.Length-1if ArgNum=0+offsetThen
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")returnendifif s.Chars(0)="/"then
opt=s.ToUpper()if opt.IndexOf("C")=-1and opt.IndexOf("A")=-1then
opt=opt+"W"endif
offset=1else
path=sendifEndifif ArgNum=1+offsetThen
s=CmdArgs(ArgNum)if s.ToUpper()="GET"then
isGet=TrueelseTry
dt=DateTime.Parse(s)Catch eAs Exception
Console.WriteLine("Error: Invalid datetime format")returnEndTryendifEndifif ArgNum=2+offsetThenTry
dt=DateTime.Parse(CmdArgs(ArgNum-1)+""+CmdArgs(ArgNum))ExitforCatch eAs Exception
Console.WriteLine("Error: Invalid datetime format")returnEndTryEndifNext ArgNumelse
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")returnEndIfTryIf File.Exists(path)=TrueThenif opt.IndexOf("W")>-1thenif isGetthen
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"))endifendifif opt.IndexOf("C")>-1thenif isGetthen
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"))endifendifif opt.IndexOf("A")>-1thenif isGetthen
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"))endifendifreturnendifCatch eAs Exception
Console.WriteLine("Error: {0}", e.ToString())returnEndTryTryIf File.Exists(path+".lnk")=TrueThenif opt.IndexOf("W")>-1thenif isGetthen
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"))endifendifif opt.IndexOf("C")>-1thenif isGetthen
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"))endifendifif opt.IndexOf("A")>-1thenif isGetthen
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"))endifendifreturnendifCatch eAs Exception
Console.WriteLine("Error: {0}", e.ToString())returnEndTryTryIf Directory.Exists(path)=TrueThenif opt.IndexOf("W")>-1thenif isGetthen
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"))endifendifif opt.IndexOf("C")>-1thenif isGetthen
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"))endifendifif opt.IndexOf("A")>-1thenif isGetthen
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"))endifendifEndIfreturnCatch eAs Exception
Console.WriteLine("Error: {0}", e.ToString())returnEndTry
Console.WriteLine("Error: Can not find File or File.lnk or Dir [{0}]",path)returnEnd SubEnd Class
[/Quote]
\

是根据时间类型的文件名来自动读取文件名所代表的时间为修改时间吗?
好好看看问题的内容
endfly 2010-01-27
  • 打赏
  • 举报
回复
顶起来
赵4老师 2010-01-27
  • 打赏
  • 举报
回复
到我的资源http://download.csdn.net/zhao4zhong1里面下载“修改文件或文件夹日期时间的命令行工具”这里特给出源码
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
加载更多回复(9)

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧