LoginSignup
1
1

More than 5 years have passed since last update.

ディレクトリ(フォルダ)を作成するプログラム

Last updated at Posted at 2018-07-18

開発環境

OS : Microsoft Windows10 (64bit)
IDE : Microsoft Visual Studio 2012

ディレクトリ(フォルダ)を作成するプログラム

初めに新しいプロジェクトからC#を選択をして、コンソールアプリケーションを選択します。
次にプロジェクトの名前を入力します。今回はtest5と言う名前にして、右下のOKをクリックします。
↓画像の用になります。
今日の日付2.png

ソースコード


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test5
{
    class Program
    {
        static void Main()
        {
            string path = @"C:\Users\honka-1\Desktop\new\test";

            Directory.CreateDirectory(path);

            Console.WriteLine("フォルダを作成しました");
            Console.ReadKey();
        }
    }
}

実行結果↓
sample1.png
これだけだと本当にファイルが作られてかわからないので、実際ファイルを作ったファイル名かパスで確認で、検索がめんどくさい場合は次に書くソースを実行してもらうと確認出来ます。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"C:\Users\honka-1\Desktop\new\test";

            if (Directory.Exists(path))
            {
                Console.WriteLine("存在します");
            }
            else
            {
                Console.WriteLine("存在しません");
            }

            Console.ReadKey();
        }
    }
}

↓実行結果
sample2.png
実行結果みてもらうとファイルきちんとあれば画像のようになります。
ファイル作成指定ソースの場所がstring path = @"C:\Users\honka-1\Desktop\new\test";この場所になります。
\の最後の場所でファイル名を決めます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1