2024年3月13日发(作者:)

以下代码实现了创建文件夹。

1

if

(!(sPath))

2

{

3

Directory(sPath);

4

}

以下代码首先检查指定的文件夹是否存在,若存在则删除之,否则创建之。接下来移动文件夹,

在其中创建文件并统计文件夹中文件数目。

using

System;

using

;

class

Test

{

public

static

void

Main()

{

// Specify the directories you want to manipulate.

string

path = @"c:MyDir";

string

target = @"c:TestDir";

try

{

// Determine whether the directory exists.

if

(!(path))

{

// Create the directory it does not exist.

Directory(path);

}

if

((target))

{

// Delete the target to ensure it is not there.

(target, true);

}

// Move the directory.

(path, target);

// Create a file in the directory.

Text(target + @"");

// Count the files in the target directory.

ine("The number of files in {0} is {1}",

target, es(target).Length);

}

catch

(Exception e)

{

ine("The process failed: {0}", ng());

}

finally

{}

}

}

以下代码演示了如何计算文件夹大小。

1

2

3

// The following example calculates the size of a directory

// and its subdirectories, if any, and displays the total size

// in bytes.

4

5

using

System;