|
|
Add a file to the list of recent documents
|
Total Hit (3007) |
To add a file to the "Recents" folder, you just need a single API function: SHAddToRecentDocs. This function takes two parameters. The first is SHARD_PATH if you want to refer to the file with its path string, while is SHARD_PIDL if you use its identifier. The second is the path string of the file,
....Read More |
Rating
|
|
|
Checking if a Floppy Drive is ready using FileSystemObject library
|
Total Hit (3514) |
The Microsoft Scripting Runtime Library offers a FileSystemObject and a Drive object that allow you to check if a Floppy drive is ready. Before writing the code you have to add this library to your project using the References dialog window. If the library isn't contained in the list, you can downlo
....Read More |
Rating
|
|
|
Copy a directory tree
|
Total Hit (3042) |
Creating a VB routine that copies a whole directory tree can be a time-consuming job, but fortunately you don't have to do it. In fact, you can quickly create an entire folder, including all its subfolders, using the CopyFolder method of the FileSystemObject object, that is exposed by the Microsoft
....Read More |
Rating
|
|
|
Counting characters in a file
|
Total Hit (3809) |
Ever needed to count how many characters of a given type are in a file? For instance, how many alphabetical characters, or digits, or spaces? You might read each line of the file using Line Input, but you will probably to load the whole file in memory using one single operation:
«Code LangId=1»
....Read More |
Rating
|
|
|
Delete a folder and all its subfolders
|
Total Hit (3429) |
The RmDir command can delete a directory only if it doesn't contain files or sub-directories. If the directory you want to delete does contain other files or, worse, subdirectories it seems that you are forced to use a recursive routine that does the job.
A simpler solution is offered by the Dele
....Read More |
Rating
|
|
|
Get the canonical name of a file
|
Total Hit (3512) |
In many cases you may need the canonical (or absolute) name of a file, for example when you need to compare two relative file names (relative to the current directory or drive, that is) and decide whether they point to the same or different files.
You can obtain the canonical path of a file usin
....Read More |
Rating
|
|
|
|
Load a text file in one operation
|
Total Hit (2912) |
The fastest way to read a text file is using the Input$ function, as shown in this reusable procedure:
«Code LangId=1»
Function FileText (filename$) As String
Dim handle As Integer
handle = FreeFile
Open filename$ For Input As #handle
FileText = Input$(LOF(handle), handle)
....Read More |
Rating
|
|
|
Retrieve information on all available drives
|
Total Hit (3140) |
You can retrieve information about all the available drives using calls to Windows API, if you like the hard way of doing things. A much simpler solution is offered by the Microsoft Scripting Runtime library, that exposes a Drive object that lets you get all those info by querying a property:
....Read More |
Rating
|
|
|
Search a file in a directory tree using the Imagehlp DLL
|
Total Hit (3757) |
You can search a file in all the subdirectories of a given drive in VB using a recursive routine based on the Dir$ function, the FileSystemObject component, or the FindFirstFile/FindNextFile API functions. There is a fourth way you might want to try out, based on the SearchTreeForFile function embed
....Read More |
Rating
|
|
|
Using the CreateDirectory and CreateDirectoryEx API functions
|
Total Hit (6994) |
The VB's MkDir function creates a directory in a specified path. If the directory already exists, MkDir raises error 75 (Path/file access error); yet, it raises the same error code if you attempt to create the directory on a read-only drive. Even worse, in Windows NT/2K/XP workstations, if you try t
....Read More |
Rating
|
|
|
AddBackslash - Append a backslash to a path if needed
|
Total Hit (3163) |
«Code LangId=1»' Append a backslash (or any character) at the end of a path
' if it isn't there already
Function AddBackslash(Path As String, Optional Char As String = "\") As String
If Right$(Path, 1) <> Char Then
AddBackslash = Path & Char
Else
AddBackslash = Path
....Read More |
Rating
|
|
|
ChangeFileExtension - Modify the extension in a file name
|
Total Hit (2786) |
«Code LangId=1»
' Change the extension of a file name
' if the last argument is True, it adds the extension even if the file doesn't
' have one
Function ChangeFileExtension(FileName As String, Extension As String, _
Optional AddIfMissing As Boolean) As String
Dim i As Long
For
....Read More |
Rating
|
|
|
|
|
CompareFiles - Check whether two files contain the same data
|
Total Hit (3155) |
«Code LangId=1»' compare two files
' return True if they're equal
Function CompareFiles(ByVal file1 As String, ByVal file2 As String) As Boolean
Dim fnum1 As Integer, isOpen1 As Boolean
Dim fnum2 As Integer, isopen2 As Boolean
Dim buffer1 As String, buffer2 As String
Dim byt
....Read More |
Rating
|
|
|
ConcatenateFiles - Merge multiple text files in one
|
Total Hit (3098) |
«Code LangId=1»
' Concatenate a variable number of text files into a single result file
'
' Params:
' - ResultFile: the complete path of the result file you want to create
' - Separator: a string that is written when a file is added to the result
' file.
' Note: this string can conta
....Read More |
Rating
|
|
|
DirExists - Check that a directory exists
|
Total Hit (3281) |
«Code LangId=1»
' Return True if a directory exists
' (the directory name can also include a trailing backslash)
Function DirExists(DirName As String) As Boolean
On Error GoTo ErrorHandler
' test the directory attribute
DirExists = GetAttr(DirName) And vbDirectory
ErrorHandler:
....Read More |
Rating
|
|
|
|
FileExists - Check that a file exists
|
Total Hit (3810) |
«Code LangId=1»' Return True if a file exists
Function FileExists(FileName As String) As Boolean
On Error GoTo ErrorHandler
' get the attributes and ensure that it isn't a directory
FileExists = (GetAttr(FileName) And vbDirectory) = 0
ErrorHandler:
' if an error occurs, this
....Read More |
Rating
|
|
|
|
|
|
GetAllFiles - Search files in a directory or directory tree
|
Total Hit (4723) |
«code LangId=1»Private Sub Command1_Click()
Dim col As Collection
'//Get all files from C:\ (No sub folder) which are older than 5 days and newer than 30 days
Set col = GetAllFiles("c:\", "*.*", False, 30, 5)
For Each f In col
Debug.Print FileDateTime(f) & "=>" & f
....Read More |
Rating
|
|
|
|
GetAttrDescr - The attributes of a file in a readable format
|
Total Hit (2684) |
«Code LangId=1»
' The attributes of a file in a readable format.
' It works also with open files, raises an error if the file doesn't exist.
Function GetAttrDescr(filename As String) As String
Dim result As String, attr As Long
' get file attributes as a bit-coded field
attr =
....Read More |
Rating
|
|
|
GetDirectories - Returns all the subdirectories of a directory
|
Total Hit (3301) |
«Code LangId=1»' Returns a collection holding all the subdirectories in a path
' that match search attributes (optionally it returns the entire path).
Function GetDirectories(path As String, Optional Attributes As VbFileAttribute, _
Optional IncludePath As Boolean) As Collection
Dim d
....Read More |
Rating
|
|
|
|