Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ Uses Tk which is generally included as part of Python standard library.

## References

[1] "Thermo Scientific SPC File Format." Thermo Fisher Scientific, Web. 20 July 2014\. <http://ftirsearch.com/features/converters/SPCFileFormat.htm>.
[1] "Thermo Scientific SPC File Format." Thermo Fisher Scientific, Web. 20 July 2014\. <http://ftirsearch.com/features/converters/SPCFileFormat.htm>. ([archived](https://web.archive.org/web/20150131073636/http://ftirsearch.com:80/features/converters/spcfileformat.HTM))
44 changes: 30 additions & 14 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@
import spc


def is_valid_spc_file(filepath):
"""A function used to determine if the given path is an SPC file"""
return os.path.isfile(filepath) and filepath.lower().endswith('spc')

def get_files_from_path(path):
"""
A function used to generate a list of SPC files from the given path.
The function returns a list even for a single file path.
"""
path = os.path.abspath(path)
if os.path.isfile(path) and is_valid_spc_file(path):
return [path]

elif os.path.isdir(path):
build_full_path = lambda f:
all_files = map(build_full_path, os.listdir(path))
#all_files = [os.path.join(path, f) for f in os.listdir(path)]
return [filepath for filepath in all_files if is_valid_spc_file(filepath)]

else:
return []

def main():
desc = 'Converts *.spc binary files to text using the spc module'
parser = argparse.ArgumentParser(description=desc)
Expand All @@ -32,20 +54,16 @@ def main():

flist = []

# add all files from input file name
# add all valid spc files from input file name
for fn in args.filefolder:
ffn = os.path.abspath(fn)
# or directories
if os.path.isdir(ffn):
for f in os.listdir(ffn):
flist.append(os.path.join(ffn, f))
else:
flist.append(ffn)

# process files
for fpath in flist:
if fpath.lower().endswith('spc'):
flist += get_files_from_path(fn)

if len(flist) == 0:
print('No valid SPC file(s) found.')

else:
# process files
for fpath in flist:
foutp = fpath[:-4] + exten
try:
print(fpath, end=' ')
Expand All @@ -54,8 +72,6 @@ def main():
print('Converted')
except:
print('Error processing %s' % fpath)
else:
print('%s not spc file, skipping' % fpath)

if __name__ == '__main__':
main()