Skip to content

Commit

Permalink
Show 1-depth files/folders when no 0-depth files/folders is listed in…
Browse files Browse the repository at this point in the history
… the zipfile namelist
  • Loading branch information
odapg committed Dec 8, 2024
1 parent daf51e3 commit d5dbe1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ then

* Unzip a particular file/folder with ⌘↩,

* Take a Quicklook at a file with ⌃↩.
* Have a Quicklook at a file with ⌃↩.

## Remarks

Expand Down
22 changes: 16 additions & 6 deletions azb.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,19 @@ def filter_files_only(paths):
return [f for f in paths if not f.endswith('/')]

def filter_paths_in_directory(paths, directory, show_subfolder_contents):
return [f for f in paths
if f.startswith(directory)
and f != directory
and (f.lstrip(directory).rstrip('/').count('/') == 0 or show_subfolder_contents == "1")]
filtered_paths= [f for f in paths
if f.startswith(directory)
and f != directory
and (f.lstrip(directory).rstrip('/').count('/') == 0 or show_subfolder_contents == "1")
]
# Some ZIP files have files the main directory not listed in the namelist
if directory == "" and not filtered_paths:
filtered_paths= [f for f in paths
if f.startswith(directory)
and f != directory
and (f.lstrip(directory).rstrip('/').count('/') == 1 or show_subfolder_contents == "1")
]
return filtered_paths

def parent_path(my_path):
# gives the parent path to go to after ⇧↩ — with a particular form for short paths
Expand Down Expand Up @@ -190,6 +199,7 @@ def read_and_cache_zipfile(zip_file, cache_folder, cache_file):
# and returns a list of these paths

paths = list_paths(zip_file)

if not os.path.isdir(cache_folder):
try:
os.mkdir(cache_folder)
Expand Down Expand Up @@ -223,11 +233,11 @@ def main():
show_subfolder_contents = os.getenv('show_subfolder_contents')
cache_folder = os.getenv('alfred_workflow_cache')
cache_file = os.path.join(cache_folder, 'alzibro_cache')
clear_cache = os.getenv('clear_cache')
clear_cache = os.getenv('clear_cache')

# Gathering the paths from either the zip file or the cache
if starting=="1":
paths = read_and_cache_zipfile(zip_file, cache_folder, cache_file)
paths = read_and_cache_zipfile(zip_file, cache_folder, cache_file)
else:
try:
with open(cache_file,'r') as file:
Expand Down

0 comments on commit d5dbe1e

Please sign in to comment.