给定一个文件树 - 在它etc目录的目录,你会如何编写一个脚本来创建该文件树的图作为我一个字处理器文档中嵌入图形文件。 我喜欢矢量(SVG,EPS,EMF ...)文件。 该工具必须在Windows上运行,但最好是跨平台的。 该工具可以是商业,但优选不含

更新2012-02-20。 问题涉及到一个文档子项目。我不得不explan其中的文件(特别是资源和配置文件)所在的位置。 我结束了使用DOS命令树。我都抓住屏的结果(简称文件夹)和较长的文件夹重定向我到一个文本文件,然后我编辑。例如,如果一个子文件夹中包含20页单独均未我提出的观点同样重要类型的文件,我离开只是两个一个...线取代了休息。然后,我打印出来的文件再次安慰和屏幕抓住它。 屏幕抓取之前,我不得不修改前景颜色为黑色和背景色为白色,更好看和保存墨水的文档中应该被打印。

这是非常奇怪,有没有为它更好的工具。如果我有时间,我会写一个Visio扩展,也可以产生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 - 从网页:

  

在Graphviz的布局方案采取简单的文本语言图形的描述,并进行多种有用的格式,例如图像和SVG的网页图表,后记列入PDF或其他文件;或在交互式图形浏览器中显示。 (Graphviz的也支持GXL,一个XML方言。)

这是我发现创建各种盒子和线图的最简单,最高效的工具。我已经和使用Visio和的OmniGraffle,但总是有诱惑,使“只是一个更调整。”

它也很容易编写代码以产生Graphiz消耗“点文件”格式,因此自动化图产量也指日可待很好。

正如所承诺的,这是我的开罗版本。我和Lua脚本它,使用LFS走路的目录。我喜欢这些小的挑战,因为他们让我去探索的API,我想挖了很长一段时间...点击 LFS和LuaCairo都是跨平台的,所以它应该在其他系统上工作(法国的WinXP临SP3测试)。

我做了第一个版本的图形文件名作为我走在树。优点:没有内存开销。不便:我不得不预先指定图像尺寸,所以列表可能被切断

所以,我提出这个版本中,第一走在目录树中,将其存储在一个Lua表。然后,知道文件的数量,创造了画布,以适应(至少垂直)和绘图的名字。结果 您可以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")

当然,你可以改变风格。我没有画的连接线,我没有把它作为必要看到。我可任选稍后添加它们。

为什么会不只是使Windows文件系统上的文件结构和您所需的名称来填充,然后使用屏幕抓取像HyperSnap中(或无处不在的Alt-PrtScr)来捕获资源管理器窗口的一部分。

我做这个“demoing”这将有可折叠部分互联网应用程序时,我不得不创建一个看起来像我希望的项目文件。

HyperSnap中至少给出的JPG文件(可能是别人,但我从来没有费心去调查)。

或者,你可以从屏幕捕捉资源管理器的图标+/-和MS Word中使用它们绘制自身做你的图片,但我从来没有能够得到微软Word绘制检点自己。

建议使用Graphviz的好:可以生成点文件,它会做测量串,在做布局等的努力再加上它可以输出图形中的格式很多,包括向量那些<。 / p>

我发现了一个Perl程序做的恰恰是,在一个邮件列表,但我就是不能找回来!我复制的样本点文件,并研究它,因为我不知道很多这种声明的语法,我想了解多一点。

问题:与最新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

我会尝试另一方向,使用开罗,这也是能够输出多种格式。这是更多的工作(计算位置/偏移),但结构简单,不应该太硬。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top