import os, sys
def maker(inputdir, outputdir, suffix=""):
if not (chechdir(inputdir) and chechdir(outputdir)): sys.exit(0)
for pos in os.listdir(inputdir):
name = os.path.abspath(inputdir+"/"+pos)
if os.path.isdir(name):
maker(name, outputdir, suffix+"1")
else:
simlnkname = os.path.abspath(outputdir+"/"+pos)
if os.path.exists(simlnkname):
simlnkname += suffix
os.symlink(name, simlnkname)
def chechdir(directory):
if not (os.path.exists(directory) and os.path.isdir(directory)):
print "Error directory ", directory
return False
return True
if __name__ == "__main__":
inp = "dir1"
outp = "dir2"
maker(inp, outp)
Test it:
$ tree
.
├── dir1
│ ├── bash
│ ├── exe1
│ ├── paper
│ │ ├── bash
│ │ ├── file1
│ │ ├── file2
│ │ └── file3
│ └── sh1
├── dir2
└── test.py
3 directories, 8 files
$ python test.py
$ tree
.
├── dir1
│ ├── bash
│ ├── exe1
│ ├── paper
│ │ ├── bash
│ │ ├── file1
│ │ ├── file2
│ │ └── file3
│ └── sh1
├── dir2
│ ├── bash -> /home/miha/exampldir/dir1/bash
│ ├── bash1 -> /home/miha/exampldir/dir1/paper/bash
│ ├── exe1 -> /home/miha/exampldir/dir1/exe1
│ ├── file1 -> /home/miha/exampldir/dir1/paper/file1
│ ├── file2 -> /home/miha/exampldir/dir1/paper/file2
│ ├── file3 -> /home/miha/exampldir/dir1/paper/file3
│ └── sh1 -> /home/miha/exampldir/dir1/sh1
└── test.py
3 directories, 15 files
It concept, what work in linux. So it's reason to clean outp
(dir2
other words) before run it.