Skip to content

Instantly share code, notes, and snippets.

@mhweber
Created January 25, 2017 18:02
Show Gist options
  • Select an option

  • Save mhweber/882a821f6a10c42bf37286c51a21c42c to your computer and use it in GitHub Desktop.

Select an option

Save mhweber/882a821f6a10c42bf37286c51a21c42c to your computer and use it in GitHub Desktop.
Short code snippet to get a list of files in one directory that don't have corresponding file in another directory using list comprehension and sets. Also gets unique names where multiple files with same 'base' name.
import os
dir1_vars = [f.split('_')[0] for f in os.listdir(dir1) if f.count('Region01')] # files in this directory have repeating base names with '_Region##' at end, this grabs unique file names
state_vars = [f.split('_')[0] for f in os.listdir('L:/Priv/CORFiles/Geospatial_Library/Data/Project/StreamCat/FTP_Staging/StreamCat/States') if f.count('AL')] # files in this directory have repeating base names with state name at end, this grabs unique file names
missing = list(set(hydroregion_vars) - set(state_vars))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment