Recursively get the Excel list in a specific folder with python and write it to Excel.


# import libraries 
import os
import pandas as pd
from glob import glob

# Configure Folder path 
mybooks = glob(r"FOLDERPATH\**\*.xls*",recursive=True)

df = []
for mybook in mybooks:
    df.append([mybook,os.path.basename(mybook)])

# Exchange ListObject to Dataframe
df = pd.DataFrame(df)

# Dump to ExcelFile
outputFilename = "filename.xlsx"
outputFolder = r"filepath"
outputFileFullpath = outputFolder  + "\\" + outputFilename
df.to_excel(outputFileFullpath,'List')

print(
    "The output of the file is finished.\n\n\n" +
    "File output location:" + outputFolder + "\n" +
    "file name:" + outputFilename    
)

Recommended Posts

Recursively get the Excel list in a specific folder with python and write it to Excel.
[Python] Get the files in a folder with Python
How to get a list of files in the same directory with python
Get the number of specific elements in a python list
How to get the last (last) value in a list in Python
Get the value of a specific key in a list from the dictionary type in the list with Python
It is easy to execute SQL with Python and output the result in Excel
Get the list in the S3 bucket with Python and search with a specific Key. Output the Key name, last update date, and count number to a file.
Get a list of files in a folder with python without a path
Get the value of a specific key up to the specified index in the dictionary list in Python
How to get the files in the [Python] folder
How to get the date and time difference in seconds with python
[Python] Concatenate a List containing numbers and write it to an output file.
How to identify the element with the smallest number of characters in a Python list?
[Note] How to write QR code and description in the same image with python
Developed a library to get Kindle collection list in Python
How to get a list of built-in exceptions in python
Get the matched string with a regular expression and reuse it when replacing on Python3
I made a class to get the analysis result by MeCab in ndarray with python
[Python / Ruby] Understanding with code How to get data from online and write it to CSV
I tried to create a Python script to get the value of a cell in Microsoft Excel
I also tried to imitate the function monad and State monad with a generator in Python
An easy way to view the time taken in Python and a smarter way to improve it
Try to get a list of breaking news threads in Python.
Output the contents of ~ .xlsx in the folder to HTML with Python
Get the formula in an excel file as a string in Python
Write the test in a python docstring
How to get a stacktrace in python
Get the EDINET code list in Python
Write a script in Shell and Python to notify you in Slack when the process is finished
[Python] What is pip? Explain the command list and how to use it with actual examples
Find the white Christmas rate by prefecture with Python and map it to a map of Japan
[Python] The role of the asterisk in front of the variable. Divide the input value and assign it to a variable
It is surprisingly troublesome to get a list of the last login date and time of Workspaces
A memo organized by renaming the file names in the folder with python
[Introduction to Python] What is the difference between a list and a tuple?
How to write the correct shebang in Perl, Python and Ruby scripts
How to get a specific column name and index name in pandas DataFrame
Get a list of packages installed in your current environment with python
[Introduction to Python] How to sort the contents of a list efficiently with list sort
[Linux] Command to get a list of commands executed in the past
I set the environment variable with Docker and displayed it in Python
Search for Twitter keywords with tweepy and write the results to Excel
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7
Get and convert the current time in the system local timezone with python
Receive a list of the results of parallel processing in Python with starmap
[Introduction to Python] How to write a character string with the format function
[Cloudian # 5] Try to list the objects stored in the bucket with Python (boto3)
How to stop a program in python until a specific date and time
[Python / Jupyter] Translate the comment of the program copied to the clipboard and insert it in a new cell
Write a C language linked list in an object-oriented style (with code comparison between Python and Java)
I ran GhostScript with python, split the PDF into pages, and converted it to a JPEG image.
I tried to open the latest data of the Excel file managed by date in the folder with Python
[Python] How to save the installed package and install it in a new environment at once Mac environment
How to input a character string in Python and output it as it is or in the opposite direction.
Get the caller of a function in Python
Get only the subclass elements in a list
The trick to write flatten concisely in python
Let's write a Python program and run it
A python amateur tries to summarize the list ②
I want to write to a file with Python