O'Reilly logo

C# 6.0 Cookbook, 4th Edition by Jay Hilyard, Stephen Teilhet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Filesystem I/O

8.0 Introduction

This chapter deals with a number of filesystem-related subjects, such as directory- or folder-based programming tasks. Some of the more advanced topics in filesystem I/O (input/output) are also touched on, such as:

  • Locking subsections of a file

  • Monitoring for certain filesystem actions

  • Version information in files

  • File compression

Various file and directory I/O techniques are used throughout the recipes to show you how to perform tasks such as creating, opening, deleting, reading, and writing with files and directories. This is fundamental knowledge that will help you understand the file I/O recipes and how to modify them for your purposes.

A number of the recipes have been updated to use the async and await operators to help alleviate the latency you’d typically encounter when dealing with the filesystem or network when performing file I/O. Using async and await improves your code’s overall responsiveness by allowing the I/O operations to occur but not to block the calling thread as they normally would until they’ve completed.

Unless otherwise specified, you need the following using statements in any program that uses snippets or methods from this chapter:

using System;
using System.IO;

8.1 Searching for Directories or Files Using Wildcards

Problem

You are attempting to find one or more specific files or directories that may or may not exist within the current filesystem. You might need to use wildcard characters in order ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required