Home

Directories

 

Introduction

A directory is a section of a medium used to delimit a group of files. Because it is a "physical" area, it can handle operations not available on files. In fact, there are many fundamental differences between both:

  • A file is used to contain data. A directory doesn't contain data
  • A directory can contain one or more files and not vice-versa
  • A directory can contain other directories
  • A file can be moved from one directory to another. This operation is not possible vice-versa since a file cannot contain a directory

The similarities of both types are:

  • A directory or a file can be created. One of the restrictions is that two files cannot have the same name inside of the same directory. Two directories cannot have the same name inside of the same parent directory.
  • A directory or a file can be renamed. If a directory is renamed, the "path" of its files changes
  • A directory or a file can be deleted. If a directory is deleted, its files are deleted also
  • A directory or a file can be moved. If a directory moves, it "carries" all of its files to the new location
  • A directory or a file can be copied. One file can be copied from one directory to another. If a directory if copied to a new location, all of its files are also copied to the new location

Directory Operations

Before using a directory, you must first have it. You can use an existing directory if the operating system or someone else had already created one. You can also create a new directory. Directories are created and managed by various classes but the fundamental class is Directory. Additional operations are performed using the DirectoryInfo class.

Before using or creating a directory, you can first check if it exists. This is because, if a directory already exists in the location where you want to create it, you would be prevented from creating one with the same name. In the same way, if you just decide to directly use a directory that doesn't exist, the operation you want to perform may fail because the directory would not be found.

Before using or creating a directory, to check first whether it exists or not, you can call the Directory.Exists() Boolean method. Its syntax is:

Public Shared Function Exists(ByVal path As String) As Boolean

This method receives the (complete) path of the directory. If the path is verified, the method returns true. If the directory exists, the method returns false.

To create a directory, you can call the CreateDirectory() method of the Directory class.

 
 
 

Object Serialization

 

Introduction

File processing is usually thought of as the technique of storing or retrieving bits of data of values from primitive variables that, when grouped, belong to a file. This approach falls short when the information dealt with is managed at a class level. Fortunately, modern libraries allow file processing on classes. In other words, a variable declared from a class can be saved to a stream and then the saved object can be retrieved later or on another computer. This the basis of object serialization. This serialization works by manipulating a whole object as its own value rather than its member variables.

The .NET Framework supports two types of object serialization: binary and XML.

Binary serialization works by processing an object rather than its member variables. This means that, to use it, you define an object and initialize it, or "fill" it, with the necessary values and any information you judge necessary. This creates a "state" of the object. It is this state that you prepare to serialize. When you save the object, it is converted into a stream.

XML Serialization

Thanks to its flexibility and platform independent way of dealing with values, XML is always a prima candidate for value serialization. Unlike strict object serialization, but like the techniques of file processing we reviewed earlier, XML considers the value members of an object, such as its fields and properties, for serialization. This means that XML doesn't allow serializing an object as its own value, but you can implement an effective object serialization by the way you proceed.

 
 
   
 

Previous Copyright © 2009-2016, FunctionX, Inc., Inc. Home