کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی
کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی

دسترسی به سیستم فایل کامپیوتر با آبجکت FileSystemObject



موارد زیر به کراّت در این بلاگ یادآوری شده



Scripting.FileSystemObject




 پراپرتی یا ویژگیها

Properties

Drives
می توان در این مجموعه برای گرفتن درایوها لوپ زد  پراپرتی های شئ Drive را در پائینتر مشاهده کنید
'Returns a collection of all Drive objects on the computer.
Name
'Sets or returns the name of a specified file or folder.
Path
'Returns the path for a specified file, folder, or drive.
Size
'For files, returns the size, in bytes, of the specified file; for folders, returns the size, in bytes, of all files and subfolders contained in the folder.
Type
'Returns information about the type of a file or folder (for example, for files ending in .TXT, "Text Document" is returned).






Drive Object Properties : 

AvailableSpace
'Returns the amount of available space to a user on a specified drive or network share.
DriveLetter
'Returns one uppercase letter that identifies the local drive or a network share.
DriveType
'Returns the type of a specified drive.FileSystemReturns the file system in use for a specified drive.
FreeSpace
'Returns the amount of free space to a user on a specified drive or network share.
IsReady
'Returns true if the specified drive is ready, and false if not.
Path
'Returns an uppercase letter followed by a colon that indicates the path name for a specified drive.
RootFolder
'Returns a Folder object that represents the root folder of a specified drive.
SerialNumber
'Returns the serial number of a specified drive.
ShareName
'Returns the network share name for a specified drive.
TotalSize
'Returns the total size of a specified drive or network share.
VolumeName
'Sets or returns the volume name of a specified drive.



متدهای شئ FileSystemObject


Methods : 

CopyFile
CopyFolder
CreateFolder
CreateTextFile

DeleteFile
DeleteFolder
DriveExists
FileExists
FolderExists

GetAbsolutePathName
GetBaseName
'Returns the base name of a specified file or folder.
GetDrive
'Returns a Drive object corresponding to the drive in a specified path.
GetDriveName
'Returns the drive name of a specified path.
GetExtensionName
'Returns the file extension name for the last component in a specified path.
GetFile
'Returns a File object for a specified path.
GetFileName
'Returns the file name or folder name for the last component in a specified path.
GetFolder
'Returns a Folder object for a specified path.
GetParentFolderName
'Returns the name of the parent folder of the last component in a specified path.
GetSpecialFolder
'Returns the path to some of Windows' special folders.
Move
MoveFile
MoveFolder
OpenAsTextStream

'Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file.
OpenTextFile
'Opens a file and returns a TextStream object that can be used to access the file.
WriteLine
'Writes a specified string and new-line character to a TextStream file.



در ابتدا با استفاده از متد CreateObject شئ FileSystemObject را ایجاد کنید و بعد از متدها و ویژگیهای آن استفاده کنید.





آذر سال ۱۴۰۲ :













Create TextFile





VBA Code:
Sub Ger_sinal()
Dim sinal() As integer
ReDim sinal(3)
'Test values
sinal(0) = -22306
sinal(1) = 5836
sinal(2) = 0
sinal(3) = 23326
'Creates a file and puts the values in it
Dim n_arq As Integer
Dim path As String
path = "C:\Users\DELL\Desktop\App\WAVs\Sinal_VBA.wav"
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(path, True)
a.Close
n_arq = FreeFile
Open path For Binary As n_arq
Put n_arq, , sinal
Close n_arq
End Sub







FileSystemObject



("Set fso=CreateObject("Scripting.FileSystemObject
    (Set fld = fso.GetFolder(strSourcePath

For Each sfldr in fld.Subfolders
Debug.Print sfldr.Name
Next

 گرفتن فایل های داخل فولدر 

Set fls=fld.Files
 For Each f In  fls
Debug.Print f.Name
Next


MethodDescription
CopyFileUsed to copy an existing file.
CopyFolderUsed to copy an existing folder.
CreateFolderUsed to create a folder.
CreateTextFileUsed to create a text file.
DeleteFileUsed to delete a file.
DeleteFolderUsed to delete a folder.
DriveExistsUsed to determine whether a drive exists.
FileExistsUsed to determine whether a file exists.
FolderExistsUsed to determine whether a folder exists.
GetAbsolutePathNameUsed to return the full path name.
GetDriveUsed to return a specified drive.
GetDriveNameUsed to return the drive name.
GetFileUsed to return a specified file.
GetFileNameUsed to return the file name.
GetFolderUsed to return a specified folder.
GetParentFolderNameUsed to return the name of the parent folder.
GetTempNameUsed to create and return a string representing a file name.
MoveFileUsed to move a file.
MoveFolderUsed to move a folder.
OpenTextFileUsed to open an existing text file


r = Range("A65536").End(xlUp).Row + 1

For Each FileItem In SourceFolder.Files

    'Display file properties
     Cells(r, 1).Formula = FileItem.Name
     Cells(r, 2).Formula = FileItem.Path
     Cells(r, 3).Formula = FileItem.Size
     Cells(r, 4).Formula = FileItem.DateCreated
     Cells(r, 5).Formula = FileItem.DateLastModified
     
     r = r + 1
     
Next FileItem