-
I need to know how to modify a file's properties. I've created a program that will temporarily place a different one in startup and because they're off a CD it's properties set it as ARCHIVE. Because it's archived I can't delete it. I need to know how to do this. The KILL function is what I've been trying to use. If anyone out there knows how to do this I really need to know.
Thanks in advance, Zaphod64831
-
Look at the GetAttr and SetAttr commands.
-
Code:
Get and change a file's dates
Tip by Sam Huggill
Option Explicit
Public Const OFS_MAXPATHNAME = 260
Public Const OF_READWRITE = &H2
Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public 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 Long
End Type
Public Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Public Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Public Declare Function GetFileTime Lib "kernel32" _
(ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime _
As FILETIME, lpLastWriteTime As FILETIME) As Long
Public Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, _
lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime _
As FILETIME) As Long
Public Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime _
As FILETIME, lpSystemTime As SYSTEMTIME) As Long
Public Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime _
As SYSTEMTIME, lpFileTime As FILETIME) As Long
Public Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As _
String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hFile As Long) As Long
Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Public Const SEE_MASK_INVOKEIDLIST = &HC
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
Public Const SEE_MASK_FLAG_NO_UI = &H400
Declare Function ShellExecuteEX Lib "shell32.dll" Alias _
"ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long
Public Function GetFileDateString(CT As FILETIME) As String
Dim ST As SYSTEMTIME
Dim r As Long
Dim ds As Single
'convert the passed FILETIME to a
'valid SYSTEMTIME format for display
r = FileTimeToSystemTime(CT, ST)
If r Then
ds = DateSerial(ST.wYear, ST.wMonth, ST.wDay)
GetFileDateString = Format$(ds, "DDDD MMMM D, YYYY")
Else: GetFileDateString = ""
End If
End Function
Public Function GetSystemDateString(ST As SYSTEMTIME) As String
Dim r As Long
Dim ds As Single
ds = DateSerial(ST.wYear, ST.wMonth, ST.wDay)
If ds Then
GetSystemDateString = Format$(ds, "DDDD MMMM D, YYYY")
Else
GetSystemDateString = "error!"
End If
End Function
Private Sub cmdChange_Click()
'variables required
Dim r As Long
Dim hFile As Long
Dim fName As String
Dim tmp As String
'structures required
Dim OFS As OFSTRUCT
Dim SYS_TIME As SYSTEMTIME
Dim FT_CREATE As FILETIME
Dim FT_ACCESS As FILETIME
Dim FT_WRITE As FILETIME
Dim NEW_TIME As FILETIME
'assign the textbox entry to the filename
fName = (txtFileName)
'open the file
hFile = OpenFile(fName, OFS, OF_READWRITE)
'get the FILETIME info for the created,
'accessed and last write info
r = GetFileTime(hFile, FT_CREATE, FT_ACCESS, FT_WRITE)
'----- debug only --------------------------- 'show the system time info
tmp = "Date Created:" & vbTab & GetFileDateString(FT_CREATE) & vbCrLf
tmp = tmp & "Last Access:" & vbTab & GetFileDateString(FT_ACCESS) & vbCrLf
tmp = tmp & "Last Modified:" & vbTab & GetFileDateString(FT_WRITE)
txtOriginal = tmp '--------------------------------------------
'obtain the local system time
'(adjusts for the GMT deviation
'of the local time zone)
GetLocalTime SYS_TIME
'----- debug only --------------------------- 'show the system time info
tmp = ""
tmp = "Day:" & vbTab & SYS_TIME.wDay & vbCrLf
tmp = tmp & "Month:" & vbTab & SYS_TIME.wMonth & vbCrLf
tmp = tmp & "Year:" & vbTab & SYS_TIME.wYear & vbCrLf
tmp = tmp & "String:" & vbTab & GetSystemDateString(SYS_TIME)
txtSystemDate = tmp '--------------------------------------------
'convert the system time to a valid file time
r = SystemTimeToFileTime(SYS_TIME, NEW_TIME)
'set the created, accessed and modified dates all
'to the new dates. A null (0&) could be passed as
'any of the NEW_TIME parameters to leave that date unchanged.
r = SetFileTime(hFile, NEW_TIME, NEW_TIME, NEW_TIME)
're-read the updated FILETIME info for the created,
'accessed and last write info
r = GetFileTime(hFile, FT_CREATE, FT_ACCESS, FT_WRITE)
'----- debug only --------------------------- 'show the system time info
tmp = "New Date Created:" & vbTab & GetFileDateString(FT_CREATE) & vbCrLf
tmp = tmp & "New Last Access:" & vbTab & GetFileDateString(FT_ACCESS) & vbCrLf
tmp = tmp & "New Last Modified:" & vbTab & GetFileDateString(FT_WRITE)
txtChanged = tmp '--------------------------------------------
'clean up by closing the file
r = CloseHandle(hFile)
End Sub
Private Sub cmdProveIt_Click()
Dim SEI As SHELLEXECUTEINFO
Dim r As Long
'Fill in the SHELLEXECUTEINFO structure
'and call the ShellExecuteEX API
With SEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI
.hwnd = Me.hwnd
.lpVerb = "properties"
.lpFile = (txtFileName)
.lpParameters = vbNullChar
.lpDirectory = vbNullChar
.nShow = 0
.hInstApp = 0
.lpIDList = 0
End With
'call the API
r = ShellExecuteEX(SEI)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set Form1 = Nothing
End Sub
-
<?>
What I do is set the file's attributes to normal
and then I kill the little sucker...
'To set back to normal (archive) attrib
SetAttr "yourfile.ext", vbNormal