파일 트리 다이어그램을 그리는 데 사용할 도구
디렉토리 등이 있는 디렉토리인 파일 트리가 주어지면, 워드 프로세서 문서에 내장할 수 있는 그래픽 파일로 파일 트리 다이어그램을 만드는 스크립트를 어떻게 작성하시겠습니까?벡터(SVG, EPS, EMF 등) 파일을 선호합니다.이 도구는 윈도우즈에서 실행되어야 하지만 가급적이면 교차 플랫폼을 사용해야 합니다.이 도구는 상업적일 수 있지만 무료인 것이 좋습니다.
업데이트 2012-02-20.이 질문은 문서 하위 프로젝트와 관련이 있습니다.파일(특히 리소스 및 구성 파일)이 어디에 있는지 설명해야 했습니다.저는 도스트리 명령어를 사용하게 되었습니다.두 화면 모두 결과(짧은 폴더의 경우)를 캡처했고 더 긴 폴더의 경우 텍스트 파일로 리디렉션한 다음 편집했습니다.예를 들어 하위 폴더에 20개의 유사한 유형의 파일이 포함되어 있지만 개별적으로 중요하지 않은 경우 두 개만 남기고 나머지는 하나로 교체했습니다...라인. 그리고 나서 다시 파일을 출력해서 콘솔에 넣고 화면을 잡았습니다.화면을 잡기 전에는 전경색을 검은색으로, 배경색을 흰색으로 수정해야 했습니다. 더 보기 좋게 인쇄할 수 있도록 문서에 잉크를 저장해야 했습니다.
그것을 위한 더 좋은 도구가 없다는 것은 매우 놀라운 일입니다.시간이 있다면 Visio Extension을 작성하거나 SVG를 생성하는 명령줄을 작성할 것입니다. SVG는 HTML5 하위 표준이므로 온라인 설명서에 고통 없이 포함될 수 있습니다.
2017-10-17 업데이트.이 질문이 SO에 속하지 않아 삭제되어 죄송합니다.그래서 제가 다시 말을 했습니다.위지위그 도구가 아니라 스크립트가 필요합니다.따라서 스크립트 언어나 라이브러리는 모두 괜찮습니다.그래서 그것은 코드 작성 질문이고, 저는 SO에 속한다고 생각합니다.
MS-DOS에서 tree명령도 사용할 수 있습니다. 예:
나무
C:\Foobar>tree
C:.
├───FooScripts
├───barconfig
├───Baz
│ ├───BadBaz
│ └───Drop
...
나무 /F
C:\Foobar>tree
C:.
├───FooScripts
│ foo.sh
├───barconfig
│ bar.xml
├───Baz
│ ├───BadBaz
│ │ badbaz.xml
│ └───Drop
...
트리 / A
C:\Foobar>tree /A
C:.
+---FooScripts
+---barconfig
+---Baz
¦ +---BadBaz
¦ \---Drop
...
나무/F/A
C:\Foobar>tree /A
C:.
+---FooScripts
¦ foo.sh
+---barconfig
¦ bar.xml
+---Baz
¦ +---BadBaz
¦ ¦ badbaz.xml
¦ \---Drop
...
구문
tree[drive:][path] [/F] [/A]
drive:\path파일을 나열하지 않고 디렉터리 구조를 표시하기 위한 디스크가 들어 있는 드라이브 및 디렉터리.
/F모든 디렉토리에 있는 모든 파일을 포함합니다.
/A선을 연결하는 데 사용되는 그래픽 문자를 그래픽 문자 대신 외부 문자로 바꿉니다./a는 그래픽 문자를 지원하지 않는 코드 페이지와 함께 사용되며 그래픽 문자를 제대로 해석하지 않는 프린터로 출력을 보냅니다.
Graphviz - 웹 페이지에서:
그래프비즈 레이아웃 프로그램은 간단한 텍스트 언어로 그래프를 설명하고 웹 페이지에 대한 이미지 및 SVG, PDF 또는 기타 문서에 포함하기 위한 Postscript 또는 대화형 그래프 브라우저에 표시와 같은 유용한 형식으로 다이어그램을 만듭니다(그래프비즈는 XML 방언인 GXL도 지원합니다).
이것은 다양한 상자와 선 그림을 만드는 가장 간단하고 생산적인 도구입니다.저는 Visio와 OmniGraffle을 가지고 있고 사용하지만 항상 "한 번만 더 조정"하고 싶은 유혹이 있습니다.
또한 Graphiz가 사용하는 "도트 파일" 형식을 생성하는 코드를 작성하는 것이 매우 쉬워서 자동 다이어그램 생성도 쉽게 사용할 수 있습니다.
Windows 파일 시스템에서 파일 구조를 만들고 원하는 이름으로 채운 다음 HyperSnap(또는 유비쿼터스 Alt-PrtScr)과 같은 화면 그래버를 사용하여 탐색기 창의 일부를 캡처할 수 없는 이유는 무엇입니까?
접을 수 있는 섹션이 있는 인터넷 애플리케이션을 '삭제'할 때 이 작업을 수행했습니다. 원하는 항목처럼 보이는 파일을 만들어야 했습니다.
HyperSnap은 적어도 JPG를 제공합니다(다른 것들도 있겠지만 저는 조사해 본 적이 없습니다).
또는 탐색기에서 +/- 아이콘을 화면에 캡처하여 MS Word Draw 자체에서 사용하여 사진을 만들 수 있지만 MS Word Draw가 제대로 작동하도록 할 수는 없습니다.
약속한 대로, 여기 제 카이로 버전이 있습니다.Lua와 함께 스크립트를 작성했습니다. lfs를 사용하여 디렉토리를 이동했습니다.저는 이러한 작은 도전들이 제가 오랫동안 발굴하고 싶었던 API들을 탐색할 수 있게 해주기 때문에 매우 좋아합니다.
는 모두 Pro 됨). lfs와 LuaCairo는 WinXP Pro SP3에서 작동합니다.
저는 나무를 걸으면서 첫 번째 버전의 도면 파일 이름을 만들었습니다.장점: 메모리 오버헤드 없음.불편 사항:이미지 크기를 미리 지정해야 하기 때문에 목록이 잘릴 것 같습니다.
그래서 저는 이 버전을 만들었습니다. 먼저 디렉토리 트리를 걸어 루아 테이블에 저장했습니다.그런 다음 파일 수를 파악하여 적합한 캔버스를 만들고(수직 이상) 이름을 그립니다.
PNG 렌더링과 SVG 렌더링을 쉽게 전환할 수 있습니다.후자의 문제: 카이로는 SVG의 텍스트 기능을 사용하는 대신 문자를 그리면서 낮은 수준에서 생성합니다.적어도 글꼴이 없는 시스템에서도 정확한 렌더링을 보장합니다.하지만 파일이 더 큽니다...파일을 후 가 되지 .svgz 파일을 가진 후 압축하면 별로 문제가 되지 않습니다.
또는 SVG를 직접 생성하는 것이 그리 어렵지 않을 것입니다. 저는 과거에 Lua를 사용하여 SVG를 생성했습니다.
-- LuaFileSystem <http://www.keplerproject.org/luafilesystem/>
require"lfs"
-- LuaCairo <http://www.dynaset.org/dogusanh/>
require"lcairo"
local CAIRO = cairo
local PI = math.pi
local TWO_PI = 2 * PI
--~ local dirToList = arg[1] or "C:/PrgCmdLine/Graphviz"
--~ local dirToList = arg[1] or "C:/PrgCmdLine/Tecgraf"
local dirToList = arg[1] or "C:/PrgCmdLine/tcc"
-- Ensure path ends with /
dirToList = string.gsub(dirToList, "([^/])$", "%1/")
print("Listing: " .. dirToList)
local fileNb = 0
--~ outputType = 'svg'
outputType = 'png'
-- dirToList must have a trailing slash
function ListDirectory(dirToList)
local dirListing = {}
for file in lfs.dir(dirToList) do
if file ~= ".." and file ~= "." then
local fileAttr = lfs.attributes(dirToList .. file)
if fileAttr.mode == "directory" then
dirListing[file] = ListDirectory(dirToList .. file .. '/')
else
dirListing[file] = ""
end
fileNb = fileNb + 1
end
end
return dirListing
end
--dofile[[../Lua/DumpObject.lua]] -- My own dump routine
local dirListing = ListDirectory(dirToList)
--~ print("\n" .. DumpObject(dirListing))
print("Found " .. fileNb .. " files")
--~ os.exit()
-- Constants to change to adjust aspect
local initialOffsetX = 20
local offsetY = 50
local offsetIncrementX = 20
local offsetIncrementY = 12
local iconOffset = 10
local width = 800 -- Still arbitrary
local titleHeight = width/50
local height = offsetIncrementY * (fileNb + 1) + titleHeight
local outfile = "CairoDirTree." .. outputType
local ctxSurface
if outputType == 'svg' then
ctxSurface = cairo.SvgSurface(outfile, width, height)
else
ctxSurface = cairo.ImageSurface(CAIRO.FORMAT_RGB24, width, height)
end
local ctx = cairo.Context(ctxSurface)
-- Display a file name
-- file is the file name to display
-- offsetX is the indentation
function DisplayFile(file, bIsDir, offsetX)
if bIsDir then
ctx:save()
ctx:select_font_face("Sans", CAIRO.FONT_SLANT_NORMAL, CAIRO.FONT_WEIGHT_BOLD)
ctx:set_source_rgb(0.5, 0.0, 0.7)
end
-- Display file name
ctx:move_to(offsetX, offsetY)
ctx:show_text(file)
if bIsDir then
ctx:new_sub_path() -- Position independent of latest move_to
-- Draw arc with absolute coordinates
ctx:arc(offsetX - iconOffset, offsetY - offsetIncrementY/3, offsetIncrementY/3, 0, TWO_PI)
-- Violet disk
ctx:set_source_rgb(0.7, 0.0, 0.7)
ctx:fill()
ctx:restore() -- Restore original settings
end
-- Increment line offset
offsetY = offsetY + offsetIncrementY
end
-- Erase background (white)
ctx:set_source_rgb(1.0, 1.0, 1.0)
ctx:paint()
--~ ctx:set_line_width(0.01)
-- Draw in dark blue
ctx:set_source_rgb(0.0, 0.0, 0.3)
ctx:select_font_face("Sans", CAIRO.FONT_SLANT_NORMAL, CAIRO.FONT_WEIGHT_BOLD)
ctx:set_font_size(titleHeight)
ctx:move_to(5, titleHeight)
-- Display title
ctx:show_text("Directory tree of " .. dirToList)
-- Select font for file names
ctx:select_font_face("Sans", CAIRO.FONT_SLANT_NORMAL, CAIRO.FONT_WEIGHT_NORMAL)
ctx:set_font_size(10)
offsetY = titleHeight * 2
-- Do the job
function DisplayDirectory(dirToList, offsetX)
for k, v in pairs(dirToList) do
--~ print(k, v)
if type(v) == "table" then
-- Sub-directory
DisplayFile(k, true, offsetX)
DisplayDirectory(v, offsetX + offsetIncrementX)
else
DisplayFile(k, false, offsetX)
end
end
end
DisplayDirectory(dirListing, initialOffsetX)
if outputType == 'svg' then
cairo.show_page(ctx)
else
--cairo.surface_write_to_png(ctxSurface, outfile)
ctxSurface:write_to_png(outfile)
end
ctx:destroy()
ctxSurface:destroy()
print("Found " .. fileNb .. " files")
물론, 당신은 스타일을 바꿀 수 있습니다.저는 연결선을 그리지 않았고, 필요하다고 보지 않았습니다.나중에 선택적으로 추가할 수도 있습니다.
Graphviz를 사용하라는 조언은 좋습니다. 점 파일을 생성하면 문자열 측정, 레이아웃 등의 힘든 작업을 수행할 수 있습니다.또한 벡터 형식을 포함한 다양한 형식으로 그래프를 출력할 수 있습니다.
메일링 목록에서 바로 그렇게 하는 펄 프로그램을 찾았지만 다시 찾을 수가 없습니다!저는 이 선언적 구문에 대해 잘 모르기 때문에 샘플 도트 파일을 복사하여 연구했습니다.
문제: 최신 Graphviz에서는 원본 그래프와 (손으로) 작성한 그래프 모두에 오류(또는 최종 다이어그램이 생성됨에 따라 경고)가 있습니다.일부 검색 결과 이 오류는 이전 버전에서 발견되었으며 최신 버전에서는 사라졌습니다.다시 돌아온 것 같습니다.
저는 여전히 파일을 제공합니다. 누군가에게 시작점이 될 수도 있고, 필요에 따라 충분할 수도 있습니다(물론 생성해야 합니다).
digraph tree
{
rankdir=LR;
DirTree [label="Directory Tree" shape=box]
a_Foo_txt [shape=point]
f_Foo_txt [label="Foo.txt", shape=none]
a_Foo_txt -> f_Foo_txt
a_Foo_Bar_html [shape=point]
f_Foo_Bar_html [label="Foo Bar.html", shape=none]
a_Foo_Bar_html -> f_Foo_Bar_html
a_Bar_png [shape=point]
f_Bar_png [label="Bar.png", shape=none]
a_Bar_png -> f_Bar_png
a_Some_Dir [shape=point]
d_Some_Dir [label="Some Dir", shape=ellipse]
a_Some_Dir -> d_Some_Dir
a_VBE_C_reg [shape=point]
f_VBE_C_reg [label="VBE_C.reg", shape=none]
a_VBE_C_reg -> f_VBE_C_reg
a_P_Folder [shape=point]
d_P_Folder [label="P Folder", shape=ellipse]
a_P_Folder -> d_P_Folder
a_Processing_20081117_7z [shape=point]
f_Processing_20081117_7z [label="Processing-20081117.7z", shape=none]
a_Processing_20081117_7z -> f_Processing_20081117_7z
a_UsefulBits_lua [shape=point]
f_UsefulBits_lua [label="UsefulBits.lua", shape=none]
a_UsefulBits_lua -> f_UsefulBits_lua
a_Graphviz [shape=point]
d_Graphviz [label="Graphviz", shape=ellipse]
a_Graphviz -> d_Graphviz
a_Tree_dot [shape=point]
f_Tree_dot [label="Tree.dot", shape=none]
a_Tree_dot -> f_Tree_dot
{
rank=same;
DirTree -> a_Foo_txt -> a_Foo_Bar_html -> a_Bar_png -> a_Some_Dir -> a_Graphviz [arrowhead=none]
}
{
rank=same;
d_Some_Dir -> a_VBE_C_reg -> a_P_Folder -> a_UsefulBits_lua [arrowhead=none]
}
{
rank=same;
d_P_Folder -> a_Processing_20081117_7z [arrowhead=none]
}
{
rank=same;
d_Graphviz -> a_Tree_dot [arrowhead=none]
}
}
> dot -Tpng Tree.dot -o Tree.png
Error: lost DirTree a_Foo_txt edge
Error: lost a_Foo_txt a_Foo_Bar_html edge
Error: lost a_Foo_Bar_html a_Bar_png edge
Error: lost a_Bar_png a_Some_Dir edge
Error: lost a_Some_Dir a_Graphviz edge
Error: lost d_Some_Dir a_VBE_C_reg edge
Error: lost a_VBE_C_reg a_P_Folder edge
Error: lost a_P_Folder a_UsefulBits_lua edge
Error: lost d_P_Folder a_Processing_20081117_7z edge
Error: lost d_Graphviz a_Tree_dot edge
카이로를 사용하여 다른 방향으로 시도해 보겠습니다. 카이로는 여러 형식을 내보낼 수도 있습니다.더 많은 작업(컴퓨팅 위치/오프셋)이 필요하지만, 구조는 단순하기 때문에 너무 어렵지 않습니다.
언급URL : https://stackoverflow.com/questions/347551/what-tool-to-use-to-draw-file-tree-diagram
'codememo' 카테고리의 다른 글
| 모든 npm 모듈을 전역적으로 제거하는 명령 (0) | 2023.05.23 |
|---|---|
| 다른 데이터 구조 대신 어레이를 사용하는 이유는 무엇입니까? (0) | 2023.05.23 |
| Mongoose에서 캐스케이드 스타일 삭제 (0) | 2023.05.18 |
| [] 및 {} vs list()와 dict() 중 어떤 것이 더 낫습니까? (0) | 2023.05.18 |
| 옵션 매개 변수를 오버로드로 대체하는 것이 획기적인 변화입니까? (0) | 2023.05.18 |