目录
#!/bin/python3
import os
import sys
if(len(sys.argv) != 3):
exit ("Usage: argv1:fullPath.txt argv2:partPath.txt")
try:
fullpath = open(sys.argv[1])
partpath = open(sys.argv[2])
shell = open('vimdif.sh','w')
except(OSError):
print('open file failed! reason:'+ str(reason))
fullPathL = fullpath.readlines()
partPathL = partpath.readlines()
outlist = []
for path in partPathL:
for fpath in fullPathL:
if(fpath.find(path) != -1):
print(fpath,path)
outlist.append(fpath)
break
#write shell
iter=0
shell.writelines('#!/bin/bash\n')
shell.writelines('if [ $# -lt 1 ];then\n')
shell.writelines(' echo argv:compare file dir\n')
shell.writelines(' exit\n')
shell.writelines('fi\n')
for path in outlist:
shell.writelines('pathArr['+str(iter)+']='+path)
iter = iter + 1
shell.writelines('\nfor trueFilepath in ${pathArr[*]}\n')
shell.writelines('do\n')
shell.writelines(' arr=(${trueFilepath })\n')
shell.writelines(' len=${#arr[*]}\n')
shell.writelines(' compareFile=$1${arr[${len}-1]}\n')
shell.writelines(' echo ${trueFilepath}\n')
shell.writelines(' if test -r $trueFilepath -a -r $compareFile;then\n')
shell.writelines(' vim -d $trueFilepath $compareFile\n')
shell.writelines(' fi\n')
shell.writelines('done\n')