Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import os
- import glob
- import optparse
- import sys
- import pprint
- def main():
- # Get the terminal option
- parser = optparse.OptionParser(
- "Using : python compare_filelist.py -a <dir> -b <dir>")
- parser.add_option('-a',
- dest='dname1',
- type='string',
- help='specify folder')
- parser.add_option('-b',
- dest='dname2',
- type='string',
- help='specify folder')
- (options, args) = parser.parse_args()
- if (options.dname1 is None):
- print(parser.usage)
- sys.exit()
- elif (options.dname2 is None):
- print(parser.usage)
- sys.exit()
- else:
- dname1 = options.dname1
- dname2 = options.dname2
- # Get the file list of the given extension in the specified folder
- list1 = glob.glob(os.path.join(dname1, '*.*'))
- list2 = glob.glob(os.path.join(dname2, '*.*'))
- l11 = [os.path.basename(x) for x in list1]
- l22 = [os.path.basename(y) for y in list2]
- # Get the diff between of the list
- list_file_manquants = [f2 for f2 in l22 if f2 not in l11]
- l = str()
- # Return only the file name without the file path
- for file in list_file_manquants:
- try:
- path, filename = os.path.split(file)
- l += filename + '\n'
- except:
- pass
- print(l)
- # Write the file result into a file inside the second specified folder
- with open(os.path.join(dname2, 'fichiers_manquants.txt'), 'w', encoding='utf8') as f:
- f.write(l)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment