window系统下得到一个目录下所有的文件list.txt:
然后输入:dir/b/on >list.txt 并按下回车键
/b 使用空格式(没有标题信息或摘要)。
/N 按名称(字母顺序) dir/b/n/on >list.txt
获取当前目录及子目录下所有文件名
dir /s/b *.* > list.txt
该命令会获取当前目录及子目录下所有的文件名和文件夹名
然后使用python处理提取希望得到的文件
网址链接:
https://blog.csdn.net/sd10086/article/details/52979462/
https://blog.csdn.net/ac_dao_di/article/details/57427609
由当前目录.gv的文件,生成.png图片
import os
path = os.getcwd()
#print(path)
def get_gv_list(path):is_gv_file = lambda x : any(x.endswith(extension)for extension in ['.gv'])return [x for x in os.listdir(path) if is_gv_file(x)]#print(get_gv_list(path))list_gv = get_gv_list(path)
f = open("./cmd.bat",'w')
for item in list_gv:str = '"C:\Program Files (x86)\Graphviz2.38\\bin\dot.exe" -Tpng -o 'str1 = str+item[0:len(item)-3]+".png "+item+"\n"f.write(str1)
f.close()
os.system(r'cmd.bat')
python产生状态机:
state.txt的格式:
a->b to_b
b->a to_a
a->c to_c
b->c to_c
f = open('state.txt','r')
out = open('state.gv','w');
out.write("digraph state { \n")
out.write('rankdir="LR";\n')
out.write("node [shape = circle]\n")
out.write('size = "12,12";')
out.write('edge[labelfontsize="14" fontsize="14"]\n')
for line in f.readlines():line = line.strip()#print(line)state_1 = line.split('->')#print(len(state_1))state_2 = state_1[1].split(' ')#print(state_2[0])#print(state_2[1])out_str = state_1[0]+"->"+state_2[0]+'[label="'+state_2[1]+'"]\n'out.write(out_str)
out.write("\n}")
out.close()
简单的时序图
digraph g {
rankdir="LR";
{
rank="same";
a0 [shape="record", height=.1];
a0-> a1 -> a2;
}
{
rank="same";
b0 -> b1 -> b2;
}
{
rank="same";
c0 -> c1 -> c2;
}
a1 -> b1->c2;
}
图1例子:
graph ER {
node [shape=box]; course; institute; student;
node [shape=ellipse]; {node [label="name"] name0; name1; name2;}
code; grade; number;
node [shape=diamond,style=filled,color=lightgrey]; "C-I"; "S-C"; "S-I";
name0 -- course;
code -- course;
course -- "C-I" [label="n",len=1.00];
"C-I" -- institute [label="1",len=1.00];
institute -- name1;
institute -- "S-I" [label="1",len=1.00];
"S-I" -- student [label="n",len=1.00];
student -- grade;
student -- name2;
student -- number;
student -- "S-C" [label="m",len=1.00];
"S-C" -- course [label="n",len=1.00];
label = "\n\nEntity Relation Diagram\ndrawn by NEATO";
fontsize=20;
}
图2例子:
digraph G{
{ a b c} -> { d e f }
}
图3例子:状态机
/*
The command line is
dot -Tps -Grankdir=LR states.dot > states.ps
and the file is:
*/
digraph states {
size="12,8";
rankdir=LR;
node [shape=ellipse];
empty [label = "Empty"];
stolen [label = "Stolen"];
waiting [label = "Waiting"];
full [label = "Full"];
empty -> full [label = "return"]
empty -> stolen [label = "dispatch", wt=28]
stolen -> full [label = "return"];
stolen -> waiting [label = "touch"];
waiting -> full [label = "return"];
}
状态机例2
digraph finite_state_machine {
node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8;
node [shape = circle];
rankdir=LR;
LR_0 -> LR_2 [ label = "SS(B)" ];
LR_0 -> LR_1 [ label = "SS(S)" ];
LR_1 -> LR_3 [ label = "S($end)" ];
LR_2 -> LR_6 [ label = "SS(b)" ];
LR_2 -> LR_5 [ label = "SS(a)" ];
LR_2 -> LR_4 [ label = "S(A)" ];
LR_5 -> LR_7 [ label = "S(b)" ];
LR_5 -> LR_5 [ label = "S(a)" ];
LR_6 -> LR_6 [ label = "S(b)" ];
LR_6 -> LR_5 [ label = "S(a)" ];
LR_7 -> LR_8 [ label = "S(b)" ];
LR_7 -> LR_5 [ label = "S(a)" ];
LR_8 -> LR_6 [ label = "S(b)" ];
LR_8 -> LR_5 [ label = "S(a)" ];
}
图4例子:二叉树
digraph L0 {
size = "8,8";
ordering=out;
node [shape = box];
n0 [label="E"];
n1 [label="T"];
n2 [label="F"];
n3 [label="IDENT : a "];
n4 [label="+"];
n5 [label="T"];
n6 [label="F"];
n7 [label="("];
n8 [label="E"];
n9 [label="T"];
n10 [label="F"];
n11 [label="IDENT : b "];
n12 [label="*"];
n13 [label="F"];
n14 [label="IDENT : c "];
n15 [label=")"];
n16 [label="*"];
n17 [label="F"];
n18 [label="("];
n19 [label="E"];
n20 [label="T"];
n21 [label="F"];
n22 [label="IDENT : d "];
n23 [label="*"];
n24 [label="F"];
n25 [label="IDENT : e "];
n26 [label="+"];
n27 [label="T"];
n28 [label="F"];
n29 [label="("];
n30 [label="E"];
n31 [label="T"];
n32 [label="F"];
n33 [label="IDENT : a "];
n34 [label="*"];
n35 [label="F"];
n36 [label="IDENT : b "];
n37 [label=")"];
n38 [label=")"];
n39 [label="+"];
n40 [label="T"];
n41 [label="F"];
n42 [label="IDENT : q "];
n0 -> { n1 n4 n5 n39 n40 };
n1 -> n2 ;
n2 -> n3 ;
n5 -> { n6 n16 n17 };
n6 -> { n7 n8 n15 };
n8 -> n9 ;
n9 -> { n10 n12 n13 };
n10 -> n11 ;
n13 -> n14 ;
n17 -> { n18 n19 n38 };
n19 -> { n20 n26 n27 };
n20 -> { n21 n23 n24 };
n21 -> n22 ;
n24 -> n25 ;
n27 -> n28 ;
n28 -> { n29 n30 n37 };
n30 -> n31 ;
n31 -> { n32 n34 n35 };
n32 -> n33 ;
n35 -> n36 ;
n40 -> n41 ;
n41 -> n42 ;
}
二叉树例2:
digraph "tree" {
// The problem disappeared when I removed the "ELEM3 -> ID5;" line!
//size="4,5";
ordering=out;
node [shape=plaintext];
SPEC -> DEF2;
SPEC -> DEF1;
DEF1 -> ID1;
DEF1 -> SET1;
DEF1 -> SC1;
DEF2 -> ID2;
DEF2 -> SET2;
DEF2 -> SC2;
SET1 -> OPEN1;
SET1 -> ELEM1;
SET1 -> SC3;
SET1 -> ELEM2;
SET1 -> CLOSE1;
ELEM1 -> ID3;
SET2 -> OPEN2;
SET2 -> ELEM3;
SET2 -> CLOSE2;
ELEM2 -> ID4;
ELEM3 -> ID5;
DEF1 [label=DEF];
DEF2 [label=DEF];
SET1 [label=SET];
SC1 [label=";"];
SC3 [label=";"];
SET2 [label=SET];
SC2 [label=";"];
OPEN1 [label="{"];
OPEN2 [label="{"];
CLOSE1 [label="}"];
CLOSE2 [label="}"];
ELEM1 [label=ELEMENT];
ELEM2 [label=ELEMENT];
ELEM3 [label=ELEMENT];
ID1 [label=cities];
ID2 [label=insects];
ID3 [label=andover];
ID4 [label=boston];
ID5 [label=fly];
}
图5例子
链表
digraph G {
nodesep=.05;
rankdir=LR;
node [shape=record,width=.1,height=.1];
node0 [label = "<f0> |<f1> |<f2> |<f3> |<f4> |<f5> |<f6> | ",height=2.0];
node [width = 1.5];
node1 [label = "{<n> n14 | 719 |<p> }"];
node2 [label = "{<n> a1 | 805 |<p> }"];
node3 [label = "{<n> i9 | 718 |<p> }"];
node4 [label = "{<n> e5 | 989 |<p> }"];
node5 [label = "{<n> t20 | 959 |<p> }"] ;
node6 [label = "{<n> o15 | 794 |<p> }"] ;
node7 [label = "{<n> s19 | 659 |<p> }"] ;
node0:f0 -> node1:n;
node0:f1 -> node2:n;
node0:f2 -> node3:n;
node0:f5 -> node4:n;
node0:f6 -> node5:n;
node2:p -> node6:n;
node4:p -> node7:n;
}
状态机例子
digraph "Honda-Tokoro" {
rankdir="LR" ranksep="0.2" edge[labelfontsize="8" fontsize="8" labeldistance="0.8" arrowsize="0.9" labelangle="-30" dir="none"] nodesep="0.2" node[width="0" height="0" fontsize="10"]
/*Net net00*/
n000 [label="z"]
n001->n000 [headlabel=":s:" arrowhead="invdot"]
n001 [label="m"]
n002->n001 [samehead="m002" headlabel=":r:" samearrowhead="1" arrowhead="invdot" arrowtail="inv"]
n002 [label="p1"]
n003->n002 [headlabel=":s:" arrowhead="dot"]
n003 [label="b"]
n004->n003
n004 [label="x1"]
n022->n004 [weight="0" headlabel=":s/r:" fontsize="8" arrowhead="invdot"]
n003->n002 [samehead="m000" fontsize="8" samearrowhead="1" arrowtail="inv"]
n005->n002 [samehead="m000" headlabel=":u:" fontsize="8" samearrowhead="1" arrowhead="dot" arrowtail="inv"]
n005->n001 [samehead="m002" samearrowhead="1"]
n005 [label="b"]
n006->n005 [arrowtail="inv"]
n006 [label="p2"]
n007->n006 [headlabel=":s:" arrowhead="dot"]
n007 [label="b"]
n008->n007
n008 [label="x2"]
n022->n008 [weight="0" headlabel=":s/r:" fontsize="8" arrowhead="invdot"]
n007->n006 [samehead="m001" headlabel=":u:" fontsize="8" samearrowhead="1" arrowhead="dot" arrowtail="inv"]
n009->n006 [samehead="m001" samearrowhead="1" arrowtail="inv"]
n009 [label="b2"]
n022->n009 [fontsize="8"]
n022->n009 [fontsize="8"]
n010->n006 [samehead="m001" samearrowhead="1" arrowtail="inv"]
n010 [label="b2"]
n022->n010 [fontsize="8"]
n022->n010 [fontsize="8"]
n011->n000 [headlabel=":r:" arrowhead="invdot" arrowtail="inv"]
n011 [label="n"]
n012->n011 [samehead="m005" headlabel=":s:" samearrowhead="1" arrowhead="dot"]
n012 [label="b"]
n013->n012
n013 [label="c1"]
n014->n013 [headlabel=":r:" arrowhead="invdot"]
n014 [label="b"]
n015->n014 [arrowtail="inv"]
n015 [label="y1"]
n023->n015 [weight="0" headlabel=":s/r:" fontsize="8" arrowhead="dot"]
n016->n015 [samehead="m003" headlabel=":u:" fontsize="8" samearrowhead="1" arrowhead="dot" arrowtail="inv"]
n018->n015 [samehead="m003" fontsize="8" samearrowhead="1" arrowtail="inv"]
n014->n011 [samehead="m006" headlabel=":u:" fontsize="8" samearrowhead="1" arrowhead="dot" arrowtail="inv"]
n012->n011 [samehead="m006" fontsize="8" samearrowhead="1" arrowtail="inv"]
n016->n011 [samehead="m005" samearrowhead="1"]
n016 [label="b"]
n017->n016
n017 [label="c2"]
n018->n017 [headlabel=":r:" arrowhead="invdot"]
n018 [label="b"]
n019->n018 [arrowtail="inv"]
n019 [label="y2"]
n023->n019 [weight="0" headlabel=":s/r:" fontsize="8" arrowhead="dot"]
n020->n019 [samehead="m004" headlabel=":u:" samearrowhead="1" arrowhead="dot" arrowtail="inv"]
n020 [label="b2"]
n023->n020 [fontsize="8"]
n023->n020 [fontsize="8"]
n021->n019 [samehead="m004" samearrowhead="1" arrowtail="inv"]
n021 [label="b2"]
n023->n021 [fontsize="8"]
n023->n021 [fontsize="8"]
n022 [width="0.5" label="[P]" shape="box" style="dashed" height="0.35"]
n023 [width="0.5" label="[Q]" shape="box" style="dashed" height="0.35"]
{/*L=x1*/rank=same n004 n015}
{/*L=p1*/rank=same n002 n013}
{/*L=b*/rank=same n009 n010 n020 n021}
{/*L=x2*/rank=same n008 n019}
{/*L=p2*/rank=same n006 n017}
{/*L=m*/rank=same n001 n011}
}
状态机:
digraph g {
"start" [ label = "MWGC-" ];
"n1" [ label = "WC-MG" ];
"n2" [ label = "MWC-G" ];
"n3" [ label = "C-MWG" ];
"n4" [ label = "W-MGC" ];
"n5" [ label = "MGC-W" ];
"n6" [ label = "MWG-C" ];
"n7" [ label = "G-MWC" ];
"n8" [ label = "MG-WC" ];
"n9" [ label = "-MWGC" ];
"start" -> "n1" [ label = "g" ];
"n1" -> "start" [ label = "g" ];
subgraph l { rank = same; "n3" "n4" }
subgraph r { rank = same; "n5" "n6" }
"n1" -> "n2" [ label = "m" ];
"n2" -> "n1" [ label = "m" ];
"n2" -> "n3" [ label = "w" ];
"n3" -> "n2" [ label = "w" ];
"n2" -> "n4" [ label = "c" ];
"n4" -> "n2" [ label = "c" ];
"n3" -> "n5" [ label = "g" ];
"n5" -> "n3" [ label = "g" ];
"n4" -> "n6" [ label = "g" ];
"n6" -> "n4" [ label = "g" ];
"n5" -> "n7" [ label = "c" ];
"n7" -> "n5" [ label = "c" ];
"n6" -> "n7" [ label = "w" ];
"n7" -> "n6" [ label = "w" ];
"n7" -> "n8" [ label = "m" ];
"n8" -> "n7" [ label = "m" ];
"n8" -> "n9" [ label = "g" ];
"n9" -> "n8" [ label = "g" ];
}