# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.

# %% auto 0
__all__ = ['convert']

# %% ../nbs/00_core.ipynb 2
import pandas as pd
from fastcore.script import call_parse
from fastcore.utils import globtastic
from pathlib import Path
import os

# %% ../nbs/00_core.ipynb 3
@call_parse
def convert(path:str, # path to searching for *.csv files
             file_glob:str='*.csv', # Only include files matching glob
             out_file:str='output.xlsx', # output excel file
             recursive:bool=True, # search subfolders
             delimiter=',', # delimiter to use
             quotechar='"', # quote character to escape the delimiter
             symlinks:bool=True, # follow symlinks?
             file_re:str=None, # Only include files matching regex
             folder_re:str=None, # Only enter folders matching regex
             skip_file_glob:str=None, # Skip files matching glob
             skip_file_re:str=None, # Skip files matching regex
             skip_folder_re:str=None, # Skip folders matching regex,
             ):
    "Convert csv file(s) into an excel file, if multiple csvs put on tabs."
    csvs = globtastic(path=path, recursive=recursive, symlinks=symlinks,
                       file_glob=file_glob, file_re=file_re, skip_file_glob=skip_file_glob,
                       skip_file_re=skip_file_re, skip_folder_re=skip_folder_re).map(Path)            
        
    with pd.ExcelWriter(out_file) as writer:
        for csv in csvs:
            sheet_name=csv.name[:-4]
            (pd.read_csv(csv, delimiter=delimiter, quotechar=quotechar)
             .to_excel(writer, sheet_name=sheet_name, index=False))
