0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その636

0
Posted at

概要

cscの作法、調べてみた。
指定したパスのフォルダとファイルをツリー形式でコンソールに表示する。

サンプルコード

using System;
using System.IO;

class Program {
	static void PrintTree(string path, string indent) {
		try
		{
			var directories = Directory.GetDirectories(path);
			var files = Directory.GetFiles(path);
			var entries = new string[directories.Length + files.Length];
			directories.CopyTo(entries, 0);
			files.CopyTo(entries, directories.Length);
			for (int i = 0; i < entries.Length; i++)
			{
				bool isLast = (i == entries.Length - 1);
				string currentIndent = isLast ? "└── " : "├── ";
				string nextIndent = indent + (isLast ? "	" : "│   ");
				string entry = entries[i];
				Console.WriteLine(indent + currentIndent + Path.GetFileName(entry));
				if (Directory.Exists(entry))
				{
					PrintTree(entry, nextIndent);
				}
			}
		}
		catch (UnauthorizedAccessException)
		{
			Console.WriteLine(indent + "└── [アクセス拒否]");
		}
	}
	static void Main(string[] args) {
		string targetPath = @"D:\minipro";
		if (Directory.Exists(targetPath))
		{
			Console.WriteLine(targetPath);
			PrintTree(targetPath, "");
		}
		else
		{
			Console.WriteLine("指定されたフォルダが見つかりません。");
		}
	}
}




実行結果

>dtree0

D:\minipro
├── ATMEGA8_LED
│   ├── DDL_source
│   │   ├── Release
│   │   │   └── GetSerial.dll
│   │   ├── Getseial.def
│   │   ├── GetSerial.bbs
│   │   ├── GetSerial.cpp
│   │   ├── GetSerial.dsp
│   │   ├── GetSerial.dsw
│   │   ├── GetSerial.h
│   │   ├── GetSerial.ncb
│   │   ├── GetSerial.opt
│   │   ├── GetSerial.plg
│   │   ├── ReadMe.txt
│   │   ├── StdAfx.cpp
│   │   └── StdAfx.h
│   ├── M8_LED_SOURCE
│   │   ├── Encrypt_LED.cof
│   │   ├── Encrypt_LED.dbg
│   │   ├── Encrypt_LED.hex
│   │   ├── Encrypt_LED.lk
│   │   ├── Encrypt_LED.lst
│   │   ├── Encrypt_LED.mak
│   │   ├── Encrypt_LED.mp
│   │   ├── Encrypt_LED.prj
│   │   ├── ENCRYPT_LED.SRC
│   │   ├── iom8.h
│   │   ├── LED_test.c
│   │   ├── LED_test.dp2
│   │   ├── LED_test.lis
│   │   ├── LED_test.o
│   │   ├── LED_test.s
│   │   ├── LED_test._c
│   │   └── rndom.txt
│   ├── OBJ
│   │   └── Encrypt_LED.hex
│   ├── ATMEGA8加密?例?明.txt
│   └── ?路?.jpg
├── drv
│   ├── WIN64
│   │   ├── DPInst64.exe
│   │   ├── MiniProWDF.inf
│   │   ├── MiniProWDF.sys
│   │   ├── miniprowdfx64.cat
│   │   └── wdfcoinstaller01009.dll
│   ├── zh-cn
│   │   └── dpinst.exe.mui
│   ├── dpinst.exe
│   ├── MiniProWDF.inf
│   ├── MiniProWDF.sys
│   ├── MiniProWDF_2000_XP.sys
│   ├── MiniProWDF_2003.sys
│   ├── MiniProWDF_VISTA_2008.sys
│   ├── MiniProWDF_WIN7.sys
│   ├── UsbDrvInstall.ico
│   └── wdfcoinstaller01009.dll
├── img
│   ├── Adapter001.jpg
│   ├── Adapter002.jpg
│   ├── Adapter003.jpg
│   ├── Adapter004.jpg
│   ├── Adapter005.jpg
│   ├── Adapter006.jpg
│   ├── Adapter007.jpg
│   ├── Adapter008.jpg
│   ├── Adapter009.jpg
│   ├── ICP001.jpg
│   ├── ICP002.jpg
│   ├── ICP003.jpg
│   ├── ICP004.jpg
│   ├── ICP005.jpg
│   ├── ICP006.jpg
│   ├── ICP007.jpg
│   └── ICP008.jpg
├── Serialnumber
│   ├── SOURCE_DLL
│   │   ├── Debug
│   │   ├── Getseial.def
│   │   ├── GetSerial.bbs
│   │   ├── GetSerial.cpp
│   │   ├── GetSerial.dsp
│   │   ├── GetSerial.dsw
│   │   ├── GetSerial.h
│   │   ├── GetSerial.ncb
│   │   ├── GetSerial.opt
│   │   ├── GetSerial.plg
│   │   ├── ReadMe.txt
│   │   ├── StdAfx.cpp
│   │   └── StdAfx.h
│   ├── Get_M8_LED_DATA.dll
│   └── Serial_PIC18F4550_TEST.dll
├── config.dat
├── InfoIC.dll
├── language.dat
├── MiniPro.exe
├── MiniProHelp.chm
├── Serial25Index.dat
├── Uninstall.exe
├── update.dat
└── UsbDrvInstall.exe

以上。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?