You are here: آموزش توابع API ویندوز گروه Files

گروه Files

آموزش توابع API     ویندوز           گروه: Files 

منبع: انجمن تخصصی برنامه نویسان ایران  


 

CompareFileTime, CopyFile, CreateFile, DeleteFile, GetFileAttributes, GetFileInformationByHandle, GetFileSize, GetFileTime, GetFileVersionInfo, GetFileVersionInfoSize, GetFullPathName, GetShortPathName,




نام تابع: CompareFileTime

اعلان: Declare Function CompareFileTime Lib "kernel32.dll" (lpFileTime1 As FILETIME, lpFileTime2 As FILETIME) As Long

سيستم عامل: NT , 98 , 95

توضيحات: تابع مقايسه ميكند دو زمان را كه ذخيره شدهاند با فرمت FileTime .اگر زمان نخستين زودتر از دومي باشد مقدار برگشتي 1- ميباشد و اگر دو زمان مساوي باشند مقدار برگشتي صفر و اگر اولي بعد از دومي باشد مقدار 1 برگشت داده ميشود. lpFileTime1 نخستين زمان از دو زمان براي مقايسه lpFileTime2 دومين زمان ار دو زمان براي مقايسه

مقدار بازگشتي: ---

پارامترها: ---

ثابتهاي مورد استفاده: ---

کتابخانه: Kernel32

توابع مرتبط: SystemTimeToFileTime

نکات: ---

کد نمونه:

Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type 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 Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long Private Declare Function CompareFileTime Lib "kernel32" (lpFileTime1 As FILETIME, lpFileTime2 As FILETIME) As Long Private Sub Form_Load() Dim SysTime As SYSTEMTIME, FT1 As FILETIME, FT2 As FILETIME Dim Ret As Long 'initialize SYSTEMTIME structure With SysTime .wMilliseconds = 300 .wSecond = 9 .wMinute = 59 .wHour = 17 .wMonth = 5 .wYear = 2001 .wDay = 21 .wDayOfWeek = 1 End With 'convert SYSTEMTIME to FILETIME SystemTimeToFileTime SysTime, FT1 'adjust the SYSTEMTIME structure SysTime.wMinute = SysTime.wMinute - 10 'convert SYSTEMTIME to FILETIME SystemTimeToFileTime SysTime, FT2 'compare the two FILETIMEs Ret = CompareFileTime(FT1, FT2) 'show the result Select Case Ret Case -1 MsgBox "First file time is less than second file time.", vbInformation Case 0 MsgBox "First file time is equal to second file time.", vbInformation Case 1 MsgBox "First file time is greater than second file time.", vbInformation End Select End Sub

 

نام تابع: CopyFile

اعلان: Declare Function CopyFile Lib "kernel32.dll" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long

سيستم عامل: NT , 98 , 95

توضيحات: تابع كپي ميكند يك فايل را از يك محل به محل ديگر تقريبا همانند WindowsExplorer و روشهاي مرسوم ديگر نوع كپي به مقدار متغير bFailIfExistsبستگي دارد . lpExistingFileName نام فايل اصلي براي كپي كردن lpNewFileName نام فايلي كه ميخواهيم كپي با نام آن انجام شود. bFailIfExists اگر مقدار صفر داشته باشد در صورت وجود فايل در مقصد روي آن دوباره نويسي ميكندو مقدار غيره صفر باشد تابع خطا برميگرداند

مقدار بازگشتي: ---

پارامترها: ---

ثابتهاي مورد استفاده: ---

کتابخانه: Kernel32

توابع مرتبط: DeleteFile , CreateFile , CloseHandle , SHFileOperation , CopyFileEx , MoveFile

نکات: ---

کد نمونه:

Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Private Type SHFILEOPSTRUCT hWnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAborted As Boolean hNameMaps As Long sProgress As String End Type 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 Const GENERIC_WRITE = &H40000000 Private Const OPEN_EXISTING = 3 Private Const FILE_SHARE_READ = &H1 Private Const FILE_SHARE_WRITE = &H2 Private Const FO_DELETE = &H3 Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpPathName As String, lpSecurityAttributes As Long) As Long Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh 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 MoveFile Lib "kernel32" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes 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 SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) 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 Sub Form_Load() Dim lngHandle As Long, SHDirOp As SHFILEOPSTRUCT, lngLong As Long Dim Ft1 As FILETIME, Ft2 As FILETIME, SysTime As SYSTEMTIME 'Set the dialog's title CDBox.DialogTitle = "Choose a file ..." 'Raise an error when the user pressed cancel CDBox.CancelError = True 'Show the 'Open File'-dialog CDBox.ShowOpen 'Create a new directory CreateDirectory "C:\KPD-Team", ByVal &H0 'Copy the selected file to our new directory CopyFile CDBox.filename, "C:\KPD-Team\" + CDBox.FileTitle, 0 'Rename the file MoveFile "C:\KPD-Team\" + CDBox.FileTitle, "C:\KPD-Team\test.kpd" 'Open the file lngHandle = CreateFile("C:\KPD-Team\test.kpd", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0) 'Get the file's size MsgBox "The size of the selected file is" + Str$(GetFileSize(lngHandle, lngLong)) + " bytes." 'Get the fil's time GetFileTime lngHandle, Ft1, Ft1, Ft2 'Convert the file time to the local file time FileTimeToLocalFileTime Ft2, Ft1 'Convert the file time to system file time FileTimeToSystemTime Ft1, SysTime MsgBox "The selected file was created on" + Str$(SysTime.wMonth) + "/" + LTrim(Str$(SysTime.wDay)) + "/" + LTrim(Str$(SysTime.wYear)) 'Close the file CloseHandle lngHandle 'Delete the file DeleteFile "C:\KPD-Team\test.kpd" With SHDirOp .wFunc = FO_DELETE .pFrom = "C:\KPD-Team" End With 'Delete the directory SHFileOperation SHDirOp End End Sub

 

نام تابع: CreateFile

اعلان: Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

سيستم عامل: NT , 2000 , 98 , 95 , CE

توضيحات: اين تابع يك كنسول را باز و يا ايجاد ميكند اعم از منابع مخابراتي ، دايركتوري(فقط باز ميكند) ، ديسك (فقط در NTو2000) ، فايلها ، ميلها(MailSlot) و غيره . البته واضح است اين دستور بيشتر در مورد فايلها استفاده ميگردد.داخل شي باز شده را ميتوان نوشت يا خواند و هر نوع دسترسي داشت . پس از پايان برنامه با استفاده از هندل ايجاد شده توسط تابع شي باز شده را بوسيله تابع CloseHandle بايد بست.

مقدار بازگشتي: اگر تابع با اشكال مواجه شود مقدار 1- برميگرداند(با استفاده از GetLastErrorميتوان به نوع خطا پي برد) و اگر تابع موفقيت آميز باشد مقدار هندل را برميگرداند.

پارامترها: lpFileName نام فايل يا هر شي ديگر جهت باز كردن يا ايجاد كردن. dwDesiredAccess تركيبي از چند فلگ براي قابليت هاي خواندن و نوشتن GENERIC_READ قابليت خواندن داده از فايل يا هر شي ديگر GENERIC_WRITE قابليت نوشتن داده در فايل يا هر شي ديگر dwShareMode تركيبي از فلگهاي مختلف جهت خواندن يا نوشتن روي يك شي توسط برنامه هاي ديگر در مدتي كه برنامه شما در حال اجرا ميباشد(به صورت مشترك) FILE_SHARE_READ اجازه خواندن داده را به برنامه ديگر ميدهد FILE_SHARE_WRITE اجازه نوشتن داده داخل فايل يا هر شي ديگري را به برنامه ديگر ميدهد. lpSecurityAppributes در ويندوز NTو2000 يك اتريبيوتي است از نوع SECURITY_ATTRIBUTES كه نوع حفاظت و خواص فايل يا هر شي ديگري را مشخص ميكند. در ويندوز 95و98وCE اين پارامتر مقدار صفر را داراست . توجه كنيد در ويژوال بيسيك براي مقدار صفر بايد از CLng(0) استفاده نمود. dwCreationDisposition اين پارامتر يكي از مقادير فلگهاي زير ميتواند باشد كه مشخص كننده آن است كه در صورت موجود بودن فايل يا شي نحوه خواندن (دوباره خواني)ويا ايجادكردن(ايجاد مجدد) را مشخص مينمايد. CREATE_ALWAYS اگر فايل موجود بود قبلي را پاك ميكند و فايل جديد را جايگزين منمايد. CREATE_NEW يك فايل يا شي جديد را ايجاد مينمايد در صورت موجود بودن آن خطا برميگرداند. OPEN_ALWAYS باز ميكند فايل يا هر شي را ودر صورت موجود نبودن آن را ايجاد ميكند. OPEN_EXISTING باز ميكند فايل يا شي جديد را و در صورت موجود نبودن خطابرميگرداند. TRUNCATE_EXISTING باز ميكند فايل و يا شي موجود را و محتويات داخلي آن را پاك ميكند. در صورت موجود نبودن فايل خطا برميگرداند. dwFlagsAndAttributes تركيبي از پرچمها براي تعيين نوع نوع اتريبيوت فايل يا شي كه ايجاد ميشود يا باز ميگردد. كه ميتواند يكي از مقادير يا تركيبي از آنهاباشد. FILE_ATTRIBUTE_ARCHIVE فايل آرشيو FILE_ATTRIBUTE_HIDDEN مخفي FILE_ATTRIBUTE_NORMAL اتربييوت معمولي (كه ديگر شامل هيچ اتريبيوت ديگري نميشود) FILE_ATTRIBUTE_READONLY فايل فقط خواندني FILE_ATTRIBUTE_SYSTEM فايل سيستمي FILE_FLAG_DELETE_ON_CLOSE در صورت بستن فايل حذف شود. FILE_FLAG_NO_BUFFERING از بافر و يا كش براي ذخيره استفاده نكند و مستقيم با ديسك كار كند. FILE_FLAG_OVERLAPPED اجازه ميدهد در صورت همزماني خواندن و نوشتن اطلاعات & روي هم افتادگي اطلاعات بوجود خواهد أمد. FILE_FLAG_POSIX_SEMANTICS حساس نسبت به حروف بزرگ و يا كوچك نام فايل FILE_FLAG_RANDOM_ACCESS بهينه مينمايد حافظه كش را براي دسترسي اتفاقي به قسمتهاي مختلف فايل. FILE_FLAG_SEQUENTIAL_SCAN بهينه ميكند حافظه كش را براي دسترسي مداوم از ابتاد تا انتهاي فايل FILE_FLAG_WRITE_THROUGH مستقيما ازفايل ميخواند ويا مينويسد. hTemplateFile هندل فايلي كه اتريبيوت آن را به اين فايل ميخواهيم منتقل كنيم اگر نخواهيم بايد صفر رد نماييم . توجه كنيد در ويژوال بيسيك براي مقدار صفر بايد از CLng(0) استفاده نمود.

ثابتهاي مورد استفاده: Const GENERIC_READ = &H80000000 Const GENERIC_WRITE = &H40000000 Const FILE_SHARE_READ = &H1 Const FILE_SHARE_WRITE = &H2 Const CREATE_ALWAYS = 2 Const CREATE_NEW = 1 Const OPEN_ALWAYS = 4 Const OPEN_EXISTING = 3 Const TRUNCATE_EXISTING = 5 Const FILE_ATTRIBUTE_ARCHIVE = &H20 Const FILE_ATTRIBUTE_HIDDEN = &H2 Const FILE_ATTRIBUTE_NORMAL = &H80 Const FILE_ATTRIBUTE_READONLY = &H1 Const FILE_ATTRIBUTE_SYSTEM = &H4 Const FILE_FLAG_DELETE_ON_CLOSE = &H4000000 Const FILE_FLAG_NO_BUFFERING = &H20000000 Const FILE_FLAG_OVERLAPPED = &H40000000 Const FILE_FLAG_POSIX_SEMANTICS = &H1000000 Const FILE_FLAG_RANDOM_ACCESS = &H10000000 Const FILE_FLAG_SEQUENTIAL_SCAN = &H8000000 Const FILE_FLAG_WRITE_THROUGH = &H80000000

کتابخانه: Kernel32

توابع مرتبط: SetFileTime , CloseHandle

نکات: ---

کد نمونه:

'This project needs a Common Dialog box, named CDBox. ' (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T) ' and select Microsoft Common Dialog control) Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type 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 Const GENERIC_WRITE = &H40000000 Private Const OPEN_EXISTING = 3 Private Const FILE_SHARE_READ = &H1 Private Const FILE_SHARE_WRITE = &H2 Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long Private Sub Form_Load() Dim m_Date As Date, lngHandle As Long Dim udtFileTime As FILETIME Dim udtLocalTime As FILETIME Dim udtSystemTime As SYSTEMTIME m_Date = Format(Now, "DD-MM-YY") 'Set the dialog's title CDBox.DialogTitle = "Choose a file ..." 'Set the dialog's filter CDBox.Filter = "All Files (*.*)|*.*" 'Show the 'Open File'-dialog CDBox.ShowOpen udtSystemTime.wYear = Year(m_Date) udtSystemTime.wMonth = Month(m_Date) udtSystemTime.wDay = Day(m_Date) udtSystemTime.wDayOfWeek = WeekDay(m_Date) - 1 udtSystemTime.wHour = Hour(m_Date) udtSystemTime.wMinute = Minute(m_Date) udtSystemTime.wSecond = Second(m_Date) udtSystemTime.wMilliseconds = 0 ' convert system time to local time SystemTimeToFileTime udtSystemTime, udtLocalTime ' convert local time to GMT LocalFileTimeToFileTime udtLocalTime, udtFileTime ' open the file to get the filehandle lngHandle = CreateFile(CDBox.Filename, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0) ' change date/time property of the file SetFileTime lngHandle, udtFileTime, udtFileTime, udtFileTime ' close the handle CloseHandle lngHandle MsgBox "The date of the file '" + CDBox.Filename + "' has been changed to" + Str$(m_Date), vbInformation + vbOKOnly, App.Title End Sub

 

نام تابع: DeleteFile

اعلان: Declare Function DeleteFile Lib "kernel32.dll" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

سيستم عامل: NT , 98 , 95

توضيحات: بطور كامل يك فايل را پاك ميكند.(به داخل سطل آشغال (Recycle Bin) نميفرستد و براي حذف كردن از شما تاييد نميخواهد بنابراين در استفاده از تابع بايد دقت نمود. در صورت موفق بودن مقدار يك و صفر براي ناموفق بودن(در صورت عدم وجود فايل).

مقدار بازگشتي: ---

پارامترها: lpFileName نام فايل جهت حذف

ثابتهاي مورد استفاده: ---

کتابخانه: Kernel32

توابع مرتبط: CopyFile , CreateDirectory , MoveFile , CreateFile , SHFileOperation

نکات: ---

کد نمونه:

'This program needs a Dialog box, named CDBox1 ' (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T) ' and select Microsoft Common Dialog control) Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Private Type SHFILEOPSTRUCT hWnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAborted As Boolean hNameMaps As Long sProgress As String End Type 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 Const GENERIC_WRITE = &H40000000 Private Const OPEN_EXISTING = 3 Private Const FILE_SHARE_READ = &H1 Private Const FILE_SHARE_WRITE = &H2 Private Const FO_DELETE = &H3 Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpPathName As String, lpSecurityAttributes As Long) As Long Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh 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 MoveFile Lib "kernel32" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes 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 SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) 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 Sub Form_Load() Dim lngHandle As Long, SHDirOp As SHFILEOPSTRUCT, lngLong As Long Dim Ft1 As FILETIME, Ft2 As FILETIME, SysTime As SYSTEMTIME 'Set the dialog's title CDBox.DialogTitle = "Choose a file ..." 'Raise an error when the user pressed cancel CDBox.CancelError = True 'Show the 'Open File'-dialog CDBox.ShowOpen 'Create a new directory CreateDirectory "C:\KPD-Team", ByVal &H0 'Copy the selected file to our new directory CopyFile CDBox.filename, "C:\KPD-Team\" + CDBox.FileTitle, 0 'Rename the file MoveFile "C:\KPD-Team\" + CDBox.FileTitle, "C:\KPD-Team\test.kpd" 'Open the file lngHandle = CreateFile("C:\KPD-Team\test.kpd", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0) 'Get the file's size MsgBox "The size of the selected file is" + Str$(GetFileSize(lngHandle, lngLong)) + " bytes." 'Get the fil's time GetFileTime lngHandle, Ft1, Ft1, Ft2 'Convert the file time to the local file time FileTimeToLocalFileTime Ft2, Ft1 'Convert the file time to system file time FileTimeToSystemTime Ft1, SysTime MsgBox "The selected file was created on" + Str$(SysTime.wMonth) + "/" + LTrim(Str$(SysTime.wDay)) + "/" + LTrim(Str$(SysTime.wYear)) 'Close the file CloseHandle lngHandle 'Delete the file DeleteFile "C:\KPD-Team\test.kpd" With SHDirOp .wFunc = FO_DELETE .pFrom = "C:\KPD-Team" End With 'Delete the directory SHFileOperation SHDirOp End End Sub

 

نام تابع: GetFileAttributes

اعلان: Declare Function GetFileAttributes Lib "kernel32.dll" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long

سيستم عامل: 32s , NT , 98 , 95

توضيحات: وضعيت خواص فايل يا دايركتوري را برميگرداند اين خواص عبارتند از فقط خواندني ، آرشيوي ، مخفي و الي آخر .اگر تابع به خطا برسد صفر و اگر فايل يا دايركتوري را پيدا نكند 1- و در غير آن يك مقدار برميگرداند كه با استفاده از عملگرهاي ANDوOR و... ميتوان به خواص فايل يا دايركتري پي برد. FILE_ATTRIBUTE_ARCHIVE = &H20 فايل آرشيوي(بيشتر فايلها اين چنين هستند) FILE_ATTRIBUTE_COMPRESSED = &H800 فايل موجود در يك درايو يا دايركتوري فشرده شده. FILE_ATTRIBUTE_DIRECTORY = &H10 يك دايركتوري بجاي فايل FILE_ATTRIBUTE_HIDDEN = &H2 يك فايل مخفي(بصورت عادي توسط كارربان قابل ديدن نيست) FILE_ATTRIBUTE_NORMAL = &H80 با حداقل خواص كه قابل تركيب با ديگر خواص نميباشد. FILE_ATTRIBUTE_READONLY = &H1 فايل فقط خواندني FILE_ATTRIBUTE_SYSTEM = &H4 فايل سيستم (در انحصار سيستم عامل ميباشد) lpFileName نام كامل فايل يا دايركتوري براي چك كردن خواص آن به همراه مسير كامل فايل

مقدار بازگشتي: ---

پارامترها: ---

ثابتهاي مورد استفاده: ---

کتابخانه: Kernel32

توابع مرتبط: GetFileInformationByHandle , SetFileAttributes

نکات: ---

کد نمونه:

' Display the attributes of C:\Files\program.exe Dim attribs As Long ' receives file attributes attribs = GetFileAttributes("C:\Files\program.exe") If(attribs And FILE_ATTRIBUTES_ARCHIVE)<>0 Then Debug.Print "Archive" If(attribs And FILE_ATTRIBUTES_HIDDEN)<>0 Then Debug.Print "Hidden" If(attribs And FILE_ATTRIBUTES_READONLY)<>0 Then Debug.Print "Read-only" ' etc....

 

نام تابع: GetFileInformationByHandle

اعلان: Declare Function GetFileInformationByHandle Lib "kernel32.dll" (ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long

سيستم عامل: 32s , NT , 98 , 95

توضيحات: اطلاعات مختلفي راجع به يك فايل ايجاد مينمايد . اين اطلاعات عبارتند از خواص فايل(Attribute) ، تاريخ و زمان ايجاد،آخرين دستيابي،و آخرين تغييرات روي آن و همچنين سريال ديسكي كه فايل داخل آن قرار دارد ، اندازه فايل ، تعداد ارتباط با آن فايل در سيستم و عدد انحصاري مشخصه آن ميباشد. تمامي اين اطلاعات داخل يك استراكچر عبور داده شده به تابع به نام lpFileInformation . اگر تابع صفر برگرداند خطا دارد و يك برگرداند مقدار يك برميگرداند. hFile هندل فايلي كه ميخواهيم اطلاعات آن را دريافت نماييم. lpFileInformation اطلاعات دريافتي از فايل

مقدار بازگشتي: ---

پارامترها: ---

ثابتهاي مورد استفاده: ---

کتابخانه: Kernel32

توابع مرتبط: GetFileAttributes , GetFileSize , GetFileTime

نکات: ---

کد نمونه:

' Display the serial number of the disk that file C:\MyProgram\datafile.txt ' is on -- in other words, we are finding the serial number of drive C:. Note that here we ' aren't interested in the other information we receive. Also note that the alternate declare ' of CreateFile must be used here since we're using Win 95/98 -- see its page for details. Dim hfile As Long ' receives the handle to the file Dim fileinfo As BY_HANDLE_FILE_INFORMATION ' receives info about the file Dim hexstring As String ' will receive the hexadecimal form of the serial number Dim retval As Long ' return value ' Get a handle to the file (note how the alternate declare is used): hfile = CreateFileNS("C:\MyProgram\datafile.txt", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0) If hfile = -1 Then ' if the file could not be opened Debug.Print "Could not open the file C:\MyProgram\datafile.txt." End ' abort the program End If ' Display the serial number, using hexadecimal: retval = GetFileInformationByHandle(hfile, fileinfo) ' read the information hexstring = Hex(fileinfo.dwVolumeSerialNumber) ' get the hexadecimal value of the serial number If Len(hexstring) < 8 Then ' if the string is less than 8 characters, hexstring = String("0", 8 - Len(hexstring)) & hexstring ' then right-pad it with "0"s End If Debug.Print "The serial number of C: is "; hexstring ' Close the file: retval = CloseHandle

 

نام تابع: GetFileSize

اعلان: Declare Function GetFileSize Lib "kernel32.dll" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long

سيستم عامل: 32s , NT , 98 , 95

توضيحات: اندازه و سايز فايل را برميگرداند اندازه فايل با دو مقدار 32 بيتي برگشت داده ميشود كه تركيب اين دو يك عدد 64 بيتي ميشود.براي يافتتن سايز واقعي فايل از فرمول زير استفاده نماييد ( توجه نماييد مقدار بالايي عدد سايز داخل lpFileSizeHighو نيمه پايين آن به عنوان مقدار برگشتي تابع عمل مينمايد) فرمول زير filesize = lpFileSizeHigh * 2^32 + return value سايز فايل بدست ميايد . اگر تابع مقدار 1- برگرداند به خطا رسيده است. hFile هندل فايلي كه ميخواهيم سايز آن را مشخص نماييم (اين يعني حتما فايل بايد به يكي از دو حالت فقط خواندني و يا قابل نوشتن باز شده باشد) lpFileSizeHigh نيمه بالايي اندازه فايل

مقدار بازگشتي: ---

پارامترها: ---

ثابتهاي مورد استفاده: ---

کتابخانه: Kernel32

توابع مرتبط: GetFileInformationByHandle

نکات: ---

کد نمونه:

' Display the file size of "C:\MyProgram\datafile.txt". Note how ' the alternate declare of the CreateFile function (needed to get the file's handle) ' must be used -- see that function's page for details. Dim hfile As Long ' receives a handle to the file Dim loworder As Long, highorder As Long ' receive the low- and high-order halves of the file size Dim retval As Long ' return value ' Get a handle to the file using CreateFile's alternate declare (necessary for non-Win NT). hfile = CreateFileNS("C:\MyProgram\datafile.txt", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0) If hfile = -1 Then ' error opening the file Debug.Print "Could not open file C:\MyProgram\datafile.txt" End ' abort the program End If ' Read and display that file's size in bytes. highorder = 0 ' initialize the value for high-order half loworder = GetFileSize(hfile, highorder) ' read the file's size If highorder = 0 Then ' if there is no high-order part Debug.Print "File size:"; loworder; "bytes" ' display the file size Else ' if there is a high-order part (file size >= 4.29 GB!) ' Visual Basic has no 64-bit variables, so we can't display the actual value: Debug.Print "File size:"; highorder; "* 2^32 +"; loworder; "bytes (in base-10)" ' But we can combine the two hex values to give the result in hexadecimal: Debug.Print "File size: "; Hex(highorder); Hex(loworder); " bytes (in hexadecimal)" End If ' Close the file retval = CloseHandle(hfile) ' close the handle

 

نام تابع: GetFileTime

اعلان: Declare Function GetFileTime Lib "kernel32.dll" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long

سيستم عامل: CE , 2000 , NT , 98 , 95

توضيحات: اين تابع زمانها و تاريخهاي ايجاد ، آخرين دسترسي ، آخرين تغييرات را برميگرداند. اين زمانها وتاريخها بر اساس سيستم UTC(مطابق زمان جهاني ، زمان گرينويچ GMT) ميباشد و نه زمان محلي كامپيوتر . توجه كنيد كه اين وابسته به سيستم عامل است نتيجه كاملا به وابسته به زمان فايل و سيستم است زيرا سيستم عامل زمانهاي ايجاد دسترسي و تغييرات را بطور كامل ذخيره نميكند(يعني ممكن است تاريخ نمايش داده شده تاريخ واقعي ذخيره شده نباشدزيرا تاريخ ذخيره شده بصورت مختصر ميباشد ولي براي نمايش آن را بر اساس يك سري پيش فرض كامل ميكند).

مقدار بازگشتي: اگر تابع به خطا برخورد كند مقدار صفر برميگرداند(GetLastError نوع خطا را مشخص ميكند) و اگر موفق باشد مقدار غير صفر برميگرداند.

پارامترها: hFile يك هندل به فايل كه ميخواهيم اطلاعات تاريخ آن را پيدا كنيم (بنابر اين حتما بايد فايل باز باشد) lpCreationTime تاريخ ايجاد فايل lpLastAccessTime تاريخ آخرين دسترسي به فايل lpLastWriteTime تاريخ آخرين تغييرات در فايل.

ثابتهاي مورد استفاده: ---

کتابخانه: Kernel32

توابع مرتبط: GetFileInformationByHandle , SetFileTime

نکات: ---

کد نمونه:

' Display the date on which the file C:\MyApp\test.txt was ' created. Note how the time zone conversion is necessary. Dim hFile As Long ' handle to the opened file Dim ctime As FILETIME ' receives time of creation Dim atime As FILETIME ' receives time of last access Dim mtime As FILETIME ' receives time of last modification Dim thetime As SYSTEMTIME ' used to manipulate the time Dim retval As Long ' return value ' First, open the file C:\MyApp\test.txt for read-level access. Note the ' expression necessary to pass 0 as lpSecurityAttributes. hFile = CreateFile("C:\MyApp\test.txt", GENERIC_READ, FILE_SHARE_READ, ByVal CLng(0), OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0) If hFile = -1 Then Debug.Print "Could not open the file successfully -- aborting." End ' terminate the program End If ' Next, get the creation, last-access, and last-modification times. retval = GetFileTime(hFile, ctime, atime, mtime) ' Convert the creation time to the local time zone. retval = FileTimeToLocalFileTime(ctime, ctime) ' Convert the FILETIME format to the SYSTEMTIME format. retval = FileTimeToSystemTime(ctime, thetime) ' Display the date of creation of the file to the user. Debug.Print "The file was created on "; thetime.wMonth; "-"; thetime.wDay; "-"; thetime.wYear ' Close the file to free up resources. retval = CloseHandle(hFile)

 

نام تابع: GetFileVersionInfo

اعلان: Declare Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long

سيستم عامل: 2000 , NT , 98 , 95

توضيحات: ورژن يك فايل از نوع اجراي 32بيتي را از درون آن استخراج ميكند . اطلاعات ورژن يك سري از بايتهايي هستند كه خواندن آنها مستقيما سخت ميباشد. از تابع VerQueryValue براي بازيابي قسمتي از اطلاعات مورد نياز بكار ميرود.

مقدار بازگشتي: اگر موفق باشد مقدار غير صفر برميگرداند و اگر ناموفق باشد صفر برگشت داده ميشود(GetLastError براي تعيين نوع خطا بكار ميرود)

پارامترها: lpstrFilename نام كامل به همراه مسير فايل dwHandle رزرو (بايد صفر باشد) dwLen سايز پارامتر lpData lpData يك بافر از نوع آرايه بايتي كه اطلاعات بازيافت شده در باره ورژن داخل آن قرار دارد.

ثابتهاي مورد استفاده: ---

کتابخانه: Version

توابع مرتبط: GetFileVersionInfoSize , VerQueryValue

نکات: ---

کد نمونه:

Display information about the file whose full path and filename is entered into textbox Text1. Display the version number, copyright information, and file description when button Command1 is pressed. To use this example, you obviously have to enter the filename of a 32-bit executable/DLL/etc. into Text1. Obviously, this example requires that you create a text box called Text1 and a command button called Command1. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" _ (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, _ lpData As Any) As Long Public Declare Function GetFileVersionInfoSize Lib "version.dll" Alias _ "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long Public Declare Function VerQueryValue Lib "version.dll" Alias "VerQueryValueA" (pBlock _ As Any, ByVal lpSubBlock As String, lplpBuffer As Long, puLen As Long) As Long Public Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 _ As Any, ByVal lpString2 As Any) As Long Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, _ Source As Any, ByVal Length As Long) Public Type VS_FIXEDFILEINFO dwSignature As Long dwStrucVersion As Long dwFileVersionMS As Long dwFileVersionLS As Long dwProductVersionMS As Long dwProductVersionLS As Long dwFileFlagsMask As Long dwFileFlags As Long dwFileOS As Long dwFileType As Long dwFileSubtype As Long dwFileDateMS As Long dwFileDateLS As Long End Type Public Const VFT_APP = &H1 Public Const VFT_DLL = &H2 Public Const VFT_DRV = &H3 Public Const VFT_VXD = &H5 ' *** Place the following function definitions inside a module. *** ' HIWORD and LOWORD are API macros defined below. Public Function HIWORD (ByVal dwValue As Long) As Long Dim hexstr As String hexstr = Right("00000000" & Hex(dwValue), 8) HIWORD = CLng("&H" & Left(hexstr, 4)) End Function Public Function LOWORD (ByVal dwValue As Long) As Long Dim hexstr As String hexstr = Right("00000000" & Hex(dwValue), 8) LOWORD = CLng("&H" & Right(hexstr, 4)) End Function ' This nifty subroutine swaps two byte values without needing a buffer variable. ' This technique, which uses Xor, works as long as the two values to be swapped are ' numeric and of the same data type (here, both Byte). Public Sub SwapByte (byte1 As Byte, byte2 As Byte) byte1 = byte1 Xor byte2 byte2 = byte1 Xor byte2 byte1 = byte1 Xor byte2 End Sub ' This function creates a hexadecimal string to represent a number, but it ' outputs a string of a fixed number of digits. Extra zeros are added to make ' the string the proper length. The "&H" prefix is not put into the string. Public Function FixedHex (ByVal hexval As Long, ByVal nDigits As Long) As String FixedHex = Right("00000000" & Hex(hexval), nDigits) End Function ' *** Place the following code inside the form that has Command1 and Text1. *** Private Sub Command1_Click() Dim vffi As VS_FIXEDFILEINFO ' version info structure Dim buffer() As Byte ' buffer for version info resource Dim pData As Long ' pointer to version info data Dim nDataLen As Long ' length of info pointed at by pData Dim cpl(0 To 3) As Byte ' buffer for code page & language Dim cplstr As String ' 8-digit hex string of cpl Dim dispstr As String ' string used to display version information Dim retval As Long ' generic return value ' First, get the size of the version info resource. If this function fails, then Text1 ' identifies a file that isn't a 32-bit executable/DLL/etc. nDataLen = GetFileVersionInfoSize(Text1.Text, pData) If nDataLen = 0 Then Debug.Print "Not a 32-bit executable!" Exit Sub End If ' Make the buffer large enough to hold the version info resource. ReDim buffer(0 To nDataLen - 1) As Byte ' Get the version information resource. retval = GetFileVersionInfo(Text1.Text, 0, nDataLen, buffer(0)) ' Get a pointer to a structure that holds a bunch of data. retval = VerQueryValue(buffer(0), "\", pData, nDataLen) ' Copy that structure into the one we can access. CopyMemory vffi, ByVal pData, nDataLen ' Display the full version number of the file. dispstr = Trim(Str(HIWORD(vffi.dwFileVersionMS))) & "." & _ Trim(Str(LOWORD(vffi.dwFileVersionMS))) & "." & _ Trim(Str(HIWORD(vffi.dwFileVersionLS))) & "." & _ Trim(Str(LOWORD(vffi.dwFileVersionLS))) Debug.Print "Version Number: "; dispstr ' Display the type of file it is (i.e., executable, DLL, etc.). Select Case vffi.dwFileType Case VFT_APP dispstr = "Application" Case VFT_DLL dispstr = "Dynamic Link Library (DLL)" Case VFT_DRV dispstr = "Device Driver" Case VFT_VXD dispstr = "Virtual Device Driver" Case Else dispstr = "Unknown" End Select Debug.Print "File Type: "; dispstr ' Before reading any strings out of the resource, we must first determine the code page ' and language. The code to get this information follows. retval = VerQueryValue(buffer(0), "\VarFileInfo\Translation", pData, nDataLen) ' Copy that informtion into the byte array. CopyMemory cpl(0), ByVal pData, 4 ' It is necessary to swap the first two bytes, as well as the last two bytes. SwapByte cpl(0), cpl(1) SwapByte cpl(2), cpl(3) ' Convert those four bytes into a 8-digit hexadecimal string. cplstr = FixedHex(cpl(0), 2) & FixedHex(cpl(1), 2) & FixedHex(cpl(2), 2) & _ FixedHex(cpl(3), 2) ' cplstr now represents the code page and language to read strings as. ' Read the copyright information from the version info resource. retval = VerQueryValue(buffer(0), "\StringFileInfo\" & cplstr & "\LegalCopyright", _ pData, nDataLen) ' Copy that data into a string for display. dispstr = Space(nDataLen) retval = lstrcpy(dispstr, pData) ' Display the result. Debug.Print "Copyright Info: "; dispstr ' Similarly, read a description of the file and display it. retval = VerQueryValue(buffer(0), "\StringFileInfo\" & cplstr & "\FileDescription", _ pData, nDataLen) dispstr = Space(nDataLen) retval = lstrcpy(dispstr, pData) Debug.Print "File Description: "; dispstr End Sub

 

نام تابع: GetFileVersionInfoSize

اعلان: Declare Function GetFileVersionInfoSize Lib "version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long

سيستم عامل: 2000 , NT , 98 , 95

توضيحات: طول ورژن يك فايل اجرايي 32بيتي را مشخص ميكند.اطلاعات ورژن خود بوسيله تابع GetFileVersionInfo بدست ميايد كه با فايلهاي اجرايي 16بيتي و فايلهايي كه اصلا قابليت اجرا ندارند كار نميكند

مقدار بازگشتي: اگر موفق باشد تابع سايز را (برحسب بايت) برميگرداند و در غير اين صورت مقدار صفر برگشت داده ميشود(GetLastError نوع خطا را مشخص ميكند)

پارامترها: lpstrFilename نام كامل به همرا مسير فايل lpdwHandle پارامتر رزرو .

ثابتهاي مورد استفاده: ---

کتابخانه: Version

توابع مرتبط: GetFileVersionInfo

نکات: ---

کد نمونه:

Display information about the file whose full path and filename is entered into textbox Text1. Display the version number, copyright information, and file description when button Command1 is pressed. To use this example, you obviously have to enter the filename of a 32-bit executable/DLL/etc. into Text1. Obviously, this example requires that you create a text box called Text1 and a command button called Command1. ' This code is licensed according to the terms and conditions listed here. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" _ (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, _ lpData As Any) As Long Public Declare Function GetFileVersionInfoSize Lib "version.dll" Alias _ "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long Public Declare Function VerQueryValue Lib "version.dll" Alias "VerQueryValueA" (pBlock _ As Any, ByVal lpSubBlock As String, lplpBuffer As Long, puLen As Long) As Long Public Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 _ As Any, ByVal lpString2 As Any) As Long Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, _ Source As Any, ByVal Length As Long) Public Type VS_FIXEDFILEINFO dwSignature As Long dwStrucVersion As Long dwFileVersionMS As Long dwFileVersionLS As Long dwProductVersionMS As Long dwProductVersionLS As Long dwFileFlagsMask As Long dwFileFlags As Long dwFileOS As Long dwFileType As Long dwFileSubtype As Long dwFileDateMS As Long dwFileDateLS As Long End Type Public Const VFT_APP = &H1 Public Const VFT_DLL = &H2 Public Const VFT_DRV = &H3 Public Const VFT_VXD = &H5 ' *** Place the following function definitions inside a module. *** ' HIWORD and LOWORD are API macros defined below. Public Function HIWORD (ByVal dwValue As Long) As Long Dim hexstr As String hexstr = Right("00000000" & Hex(dwValue), 8) HIWORD = CLng("&H" & Left(hexstr, 4)) End Function Public Function LOWORD (ByVal dwValue As Long) As Long Dim hexstr As String hexstr = Right("00000000" & Hex(dwValue), 8) LOWORD = CLng("&H" & Right(hexstr, 4)) End Function ' This nifty subroutine swaps two byte values without needing a buffer variable. ' This technique, which uses Xor, works as long as the two values to be swapped are ' numeric and of the same data type (here, both Byte). Public Sub SwapByte (byte1 As Byte, byte2 As Byte) byte1 = byte1 Xor byte2 byte2 = byte1 Xor byte2 byte1 = byte1 Xor byte2 End Sub ' This function creates a hexadecimal string to represent a number, but it ' outputs a string of a fixed number of digits. Extra zeros are added to make ' the string the proper length. The "&H" prefix is not put into the string. Public Function FixedHex (ByVal hexval As Long, ByVal nDigits As Long) As String FixedHex = Right("00000000" & Hex(hexval), nDigits) End Function ' *** Place the following code inside the form that has Command1 and Text1. *** Private Sub Command1_Click() Dim vffi As VS_FIXEDFILEINFO ' version info structure Dim buffer() As Byte ' buffer for version info resource Dim pData As Long ' pointer to version info data Dim nDataLen As Long ' length of info pointed at by pData Dim cpl(0 To 3) As Byte ' buffer for code page & language Dim cplstr As String ' 8-digit hex string of cpl Dim dispstr As String ' string used to display version information Dim retval As Long ' generic return value ' First, get the size of the version info resource. If this function fails, then Text1 ' identifies a file that isn't a 32-bit executable/DLL/etc. nDataLen = GetFileVersionInfoSize(Text1.Text, pData) If nDataLen = 0 Then Debug.Print "Not a 32-bit executable!" Exit Sub End If ' Make the buffer large enough to hold the version info resource. ReDim buffer(0 To nDataLen - 1) As Byte ' Get the version information resource. retval = GetFileVersionInfo(Text1.Text, 0, nDataLen, buffer(0)) ' Get a pointer to a structure that holds a bunch of data. retval = VerQueryValue(buffer(0), "\", pData, nDataLen) ' Copy that structure into the one we can access. CopyMemory vffi, ByVal pData, nDataLen ' Display the full version number of the file. dispstr = Trim(Str(HIWORD(vffi.dwFileVersionMS))) & "." & _ Trim(Str(LOWORD(vffi.dwFileVersionMS))) & "." & _ Trim(Str(HIWORD(vffi.dwFileVersionLS))) & "." & _ Trim(Str(LOWORD(vffi.dwFileVersionLS))) Debug.Print "Version Number: "; dispstr ' Display the type of file it is (i.e., executable, DLL, etc.). Select Case vffi.dwFileType Case VFT_APP dispstr = "Application" Case VFT_DLL dispstr = "Dynamic Link Library (DLL)" Case VFT_DRV dispstr = "Device Driver" Case VFT_VXD dispstr = "Virtual Device Driver" Case Else dispstr = "Unknown" End Select Debug.Print "File Type: "; dispstr ' Before reading any strings out of the resource, we must first determine the code page ' and language. The code to get this information follows. retval = VerQueryValue(buffer(0), "\VarFileInfo\Translation", pData, nDataLen) ' Copy that informtion into the byte array. CopyMemory cpl(0), ByVal pData, 4 ' It is necessary to swap the first two bytes, as well as the last two bytes. SwapByte cpl(0), cpl(1) SwapByte cpl(2), cpl(3) ' Convert those four bytes into a 8-digit hexadecimal string. cplstr = FixedHex(cpl(0), 2) & FixedHex(cpl(1), 2) & FixedHex(cpl(2), 2) & _ FixedHex(cpl(3), 2) ' cplstr now represents the code page and language to read strings as. ' Read the copyright information from the version info resource. retval = VerQueryValue(buffer(0), "\StringFileInfo\" & cplstr & "\LegalCopyright", _ pData, nDataLen) ' Copy that data into a string for display. dispstr = Space(nDataLen) retval = lstrcpy(dispstr, pData) ' Display the result. Debug.Print "Copyright Info: "; dispstr ' Similarly, read a description of the file and display it. retval = VerQueryValue(buffer(0), "\StringFileInfo\" & cplstr & "\FileDescription", _ pData, nDataLen) dispstr = Space(nDataLen) retval = lstrcpy(dispstr, pData) Debug.Print "File Description: "; dispstr End Sub

 

نام تابع: GetFullPathName

اعلان: Declare Function GetFullPathName Lib "kernel32.dll" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long

سيستم عامل: 32s , NT , 98 , 95

توضيحات: نام فايل را با نام دايركتوري موجود در آن تركيب كرده و يك نام كامل ايجاد ميكند . براي مثال اگر نام فايل شما Hello.txt باشد و مسير فايل نيز C:\My Documents\Junk باشد نتيجه تابع فوق مقدار زير ميشود C:\My Documents\Junk\hello.txt .نام كامل در يك استرينگ پاس داده شده به نام lpBuffer قرار ميگيرد ، تابع با خطا صفر برميگرداند و در صورت موفق بودن مقدار طول استرينگ lpBuffer را برگشت ميدهد. lpFileName نام فايل nBufferLength طول برحسب كاراكتر پارامتر lpBuffer lpBuffer يك استرينگ كه نام كامل رل شامل ميگردد و انتهاي آن با كاراكتر Null مشخص ميگردد. lpFilePart ؟؟؟ فعلا بدون ارزش است و مورد استفاده نيست

مقدار بازگشتي: ---

پارامترها: ---

ثابتهاي مورد استفاده: ---

کتابخانه: Kernel3

توابع مرتبط: GetShortPathName

نکات: ---

کد نمونه:

' Append the filename datafile.dat to C:\Programs\Test Dim buffer As String ' receives path and filename string Dim numchar As Long ' receives length of buffer after function call ChDir "\Programs\Test" ' change current directory to C:\Programs\Test buffer = Space(255) ' make room for buffer to receive the string numchar = GetFullPathName("datafile.dat", 255, buffer, "") ' put the result string into buffer buffer = Left(buffer, numchar) ' extract data from the returned string Debug.Print buffer ' display resulting string

 

نام تابع: GetShortPathName

اعلان: Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

سيستم عامل: 2000 , NT , 98 , 95

توضيحات: يك نام طولاني (نام فايلي كه بصورت طولاني و بيش از هشت كاراكتر است) را به فايلي با نام كوتاه 8.3 تبديل ميكند.برنامه هاي تحت داس و 16بيتي همه از فايلهايي با نام كوچك استفاده ميكنند . مثلا اگر نام فايلي در ويندوز ReallyLongFile.txt باشد تبديل به REALLY~1.TXT ميشود.

مقدار بازگشتي: اگر موفق باشد تابع طول استرينگ كپي شده در lpszShortPath رابرميگرداند.(شامل كاراكترNullنميشود) اگر به خطا بر خوردكند مقدار صفر برميگرداند(تابع GetLastError نوع خطا رامشخص ميكند).

پارامترها: lpszLongPath نام طولاني كه ميخواهد كوچك شود. lpszShortPath يك نام با فرمت 8.3 اين متغير بايد به اندازه كافي جا براي ذخيره داشته باشد. cchBuffer طول استرينگ پاس داده شده بهlpszShortPath .

ثابتهاي مورد استفاده: ---

کتابخانه: Kernel32

توابع مرتبط: GetFullPathName

نکات: ---

کد نمونه:

' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" _ (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer _ As Long) As Long ' Find the short filename equivalent of "C:\My Documents\ReadMeFirst.txt" Private Sub Command1_Click() Dim shortname As String ' receives short-filename equivalent Dim slength As Long ' receives length of short-filename equivalent ' Make room in the buffer to receive the 8.3 form of the filename. shortname = Space(256) ' Get the 8.3 form of the filename specified. slength = GetShortPathName("C:\My Documents\ReadMeFirst.txt", shortname, 256) ' Remove the trailing null and display the result. shortname = Left(shortname, slength) Debug.Print "Equivalent: "; shortname End Sub