Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
Search the Tips
Tip Bank > Visual Basic > Document Management

Document Management - Page 2

21-40 of 91     Previous     Next
IsValidPath - Validating a system path
by Marco Bellinaso
Validate a system path Example: MessageBox.Show(IsValidPath("C:\Test\Memo.txt")) ' => True MessageBox.Show(IsValidPath("\\RemotePC\Test\Memo.txt")) ' => True MessageBox.Show(IsValidPath("C:\Test\Mem|o.txt")) ' => False
EvalFileName - Ensure that the basename of a file or directory is valid
by Pan Polychronopoulos
EvalFileName ensures that the basename of a file or directory conforms to the Microsoft file naming guidelines (see MSDN webpage) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/ naming_a_file.asp Return value: True = Valid basename False = Invalid basename
Using the CreateDirectory API function
by Pan Polychronopoulos
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 ...
GetDriveTypeEx - Detect drive type, including CD or DVD driver
by Geoffrey Ferrell
take a drive letter and display a MsgBox with the type of the medium in the drive (you can delete the msgbox to achieve a silent function)
Retrieve file version information
by Francesco Balena
The System.Diagnostics.FileVersionInfo class lets you easily read file version information without having to call Windows API functions (as you have to do under previous VB versions). This class has a static GetVersionInfo method that returns a FileVersionInfo object related to a given file. ...
AddBackslash - Append a backslash to a path if needed
by Francesco Balena
Append a backslash (or any character) at the end of a path if it isn't there already
ChangeFileExtension - Modify the extension in a file name
by Francesco Balena
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
CopyDirectory - Copy a directory
by Marco Bellinaso
Copies a source directory to the destination directory. The last parameter specifies whether the files already present in the destination directory will be overwritten - Note: requires Imports System.IO - Usage: CopyDirectory("C:\Misc", "D:\MiscBackup")
GetDirectorySize - Calculate the size of a directory
by Marco Bellinaso
Returns the size of the specified directory - Note: requires Imports System.IO - Usage: Dim DirSize As Long = GetDirectorySize("D:\Projects")
LoadTextFile - Load the contents of a text file
by Marco Bellinaso
Returns the content of the specified text file Note: it can throw an exception Usage: Dim FileContent As String = LoadTextFile("C:\Autoexec.bat")
SaveTextFile - Save or append text to a file
by Marco Bellinaso
Saves a text file. If the destination file already exists, its content can be replaced, or the new content can be appended at the end of the file, according to the last parameter Note: the destination directory must exist, otherwise the file is not saved and the function returns False
Create a Touch utility
by Francesco Balena
The SetCreationTime, SetLastWriteTime, and SetLastAccessTime methods of the System.IO.Directory class let you modify the date attributes of a file or directory: ' Change the access date- and time of all files in C:\DOCS. For Each fname In Directory.GetFiles("c:\docs") File.
Create directory paths
by Francesco Balena
Visual Basic 6's MkDir command, as well as the DOS MD command, can create only one subdirectory and fail if any subdirectory on the specified path doesn't exist: ' This VB6 statement fails if C:\MyApp doesn't exist MKDIR "c:\MyApp\MyDir" Conversely, the Directory.
Display a directory tree
by Francesco Balena
Thanks to the GetDirectories and GetFiles methods of the System.IO.Directory class, you need very little code to iterate over all the directories and files of a directory tree. For example, the following code snippet prints the structure of a directory tree and (optionally) the name of files in ...
Filter file names on their names or attributes
by Francesco Balena
The GetFiles and GetDirectories methods of the System.IO.Directory class can take an argument containing wildcards, to filter the result: ' Display all the *.txt files in C:\DOCS. Dim fname As String For Each fname In Directory.GetFiles("c:\docs", "*.txt") Console.
Reading text files
by Francesco Balena
In Visual Basic .NET you read a text file by first opening a StreamReader on it, and then iterating over all its lines until its Peek method returns -1: Dim sr As New StreamReader("c:\autoexec.bat") ' Display all the text lines in the file. Do Until sr.Peek = -1 ' The ...
Create all the subdirectories for a new folder
by Francesco Balena
The System.IO.Directory class exposes a CreateDirectory method that, as its name suggests, can create a subdirectory. However, this method is even more powerful than it appears at a first glance, in that it can even create all the intermediate subdirectories, if necessary. In other ...
GetDirectorySize - Evaluate disk space used by files and subdirectories
by Francesco Balena
Retrieve the number of bytes by all the files in a directory (it doesn't account for slack space, that is unused space in disk sectors) If INCLUDESUBDIRS is true, it recursively parses all subdirectories. supports only up to 2G directories.
Counting characters in a file
by Francesco Balena
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: Open ...
SetFileSize - Trim or extend a file's size
by Francesco Balena
Extend or trim a file to a given length. If the file is extended, the added bytes are undefined
21-40 of 91     Previous     Next
Sitemap