PDA

View Full Version : چگونه خصوصیات یک فایل را تغییر دهیم ؟



moos111
سه شنبه 27 بهمن 1388, 22:11 عصر
دوستان با عرض سلام و خسته نباشید ...
می خواستم بدونم که چطوری میشه خصوصیات یک فایل (مثل یک فایل نوت پد ( xxx.txt) یا ...)، (که در properties قابل مشاهده است) را تغییر داد ؟
خصوصیاتی مثل :
تاریخ و زمان ایجاد فایل date created
و تاریخ و زمان آخرین تغییرات اعمال شده در فایل date modified

با تشکر

M.T.P
چهارشنبه 28 بهمن 1388, 11:32 صبح
تابع Setattr و FileDatetime به شما کمک خواهد کرد ، تست کنید
نرم افزار Servant Salamander هم خارج از وی بی توصیه میشه

moos111
چهارشنبه 28 بهمن 1388, 18:42 عصر
خیلی ممنون از جوابتون
می خوام بدونم که چطوری میشه تاریخ ایجاد یک فایل رو تغییر داد.

M.T.P
پنج شنبه 29 بهمن 1388, 10:58 صبح
اینم کد کاملش واسه تاریخ فایل:




Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal _
lpFileName As String, ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, ByVal NoSecurity As Long, _
ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As _
Long
Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, _
lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, _
lpLastWriteTime As FILETIME) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As _
FILETIME, lpSystemTime As SYSTEMTIME) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As _
FILETIME, lpLocalFileTime As FILETIME) As Long
Private Const GENERIC_READ = &H80000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const OPEN_EXISTING = 3
Private Const INVALID_HANDLE_VALUE = -1
' Retrieve the Create date, Modify (write) date and Last Access date of
' the specified file. Returns True if successful, False otherwise.
Function GetFileTimeInfo(ByVal FileName As String, Optional CreateDate As Date, _
Optional ModifyDate As Date, Optional LastAccessDate As Date) As Boolean
Dim hFile As Long
Dim ftCreate As FILETIME
Dim ftModify As FILETIME
Dim ftLastAccess As FILETIME
Dim ft As FILETIME
Dim st As SYSTEMTIME

' open the file, exit if error
hFile = CreateFile(FileName, GENERIC_READ, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, 0&, OPEN_EXISTING, 0&, 0&)
If hFile = INVALID_HANDLE_VALUE Then Exit Function

' read date information
If GetFileTime(hFile, ftCreate, ftLastAccess, ftModify) Then
' non zero means successful
GetFileTimeInfo = True

' convert result to date values
' first, convert UTC file time to local file time
FileTimeToLocalFileTime ftCreate, ft
' then convert to system time
FileTimeToSystemTime ft, st
' finally, make up the Date value
CreateDate = DateSerial(st.wYear, st.wMonth, _
st.wDay) + TimeSerial(st.wHour, st.wMinute, _
st.wSecond) + (st.wMilliseconds / 86400000)

' do the same for the ModifyDate
FileTimeToLocalFileTime ftModify, ft
FileTimeToSystemTime ft, st
ModifyDate = DateSerial(st.wYear, st.wMonth, _
st.wDay) + TimeSerial(st.wHour, st.wMinute, _
st.wSecond) + (st.wMilliseconds / 86400000)
' and for LastAccessDate
FileTimeToLocalFileTime ftLastAccess, ft
FileTimeToSystemTime ft, st
LastAccessDate = DateSerial(st.wYear, st.wMonth, _
st.wDay) + TimeSerial(st.wHour, st.wMinute, _
st.wSecond) + (st.wMilliseconds / 86400000)
End If

' close the file, in all cases
CloseHandle hFile
End Function