Skip to content

Commit

Permalink
fix filenames with space unix systems #4, add folder support
Browse files Browse the repository at this point in the history
- fix filenames with space unix systems #4
- add folder support
  • Loading branch information
agmmnn committed Mar 22, 2023
1 parent 3051268 commit 527410a
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions textual_filedrop/_filedrop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re
import shlex

from typing import List, Dict, Any

Expand All @@ -14,13 +15,24 @@


def _extract_filepaths(text: str) -> List[str]:
pattern = r'(?:[^\s"]|"(?:\\"|[^"])*")+'
split_filepaths = re.findall(pattern, text)
filepaths = [
i.replace("\x00", "").replace('"', "")
for i in split_filepaths
if os.path.isfile(i.replace("\x00", "").replace('"', ""))
]
split_filepaths = []
if os.name == "nt":
pattern = r'(?:[^\s"]|"(?:\\"|[^"])*")+'
split_filepaths = re.findall(pattern, text)
else:
split_filepaths = shlex.split(text)

split_filepaths = shlex.split(text)
print(split_filepaths)
filepaths = []
for i in split_filepaths:
item = i.replace("\x00", "").replace('"', "")
if os.path.isfile(item):
filepaths.append(i)
elif os.path.isdir(item):
for root, _, files in os.walk(item):
for file in files:
filepaths.append(os.path.join(root, file))
return filepaths


Expand Down

0 comments on commit 527410a

Please sign in to comment.