Moving files in a directory using excel file list - python

I am new to Python, and I was wondering if there is a way to use Shutil with an excel list of files.
I have a list of 55 files in excel which are placed within sub-folders in a single folder containing 1,500 Files.
Can anyone please guide me in the right direction for how to use the Shutil function with the excel file list to copy these files into one single folder.?
Here are the images for example:
List of Files that I want to move from one Directory to Another
There are many files in sub-directories as such, I want just the selective files from each of these folders

Related

How to make a file with combination of multiple files with different extensions(xlsx, csv)?

Hey I'm looking for answers which can be solve my issue.
1.I have a csv files in one folder
2.Excel files in other folder
3.I want combine these two folder files as a single file
Note : Data is same in both folder files in terms of columns
For file handling I recommend using the pathlib built-in python module: pathlib examples. Use the glob method to fetch all files with a given ending - .csv and .xslx
Next you can use pandas to open the csv and .xslx files - check these examples for csv files, for excel files
Once you load the data into dataframes, you can combine them into one dataframe. If necessary do some data manipulation on the columns.
And lastly you can export the combined dataframe into a csv file - use the pd.to_csv() method - documentation on the method

How to create a new dataframe with CSV file from a folder with subfolders in Pyspark in S3

Hi I'm very new to Pyspark and S3. I have problem at hand. I have a folder, which consists of subfolders and files and also files from the subfolder(all CSVs) i need to create a new dataframe or a csv file where i get contents of the files and create as a single file. Which later need to be read to a table in postgress
Can anyone please help me. I have code in python, but not sure how to go about with pyspark and S3
Try with this option.
recursiveFileLookup – recursively scan a directory for files. Using this option disables partition discovery.
df = spark.read.option("header","true").option("recursiveFileLookup","true").csv("s3://path/to/root/")

How to find out empty files from a bunch of excels, pdf files in a folder?

I download some pdfs and csv files from my server and many times the files are empty. I have to check manually all those files. Generally I get 80-90 files in a day and I am planning to write a python script for it.
I have tried below code. Please find it below:
import os
os.stat("Book1").st_size == 0
but since the size of an empty excel file is also 8 KB this isn't working.
Also it will be different case for pdf files.
I want to get all names of the blank files in a new txt file.

Python: get the list of files in a directory

I have a program in Python (Python 3 on Ubuntu 16.04) that checks for new files in a directory (.mp4 files are the result of segmenting a live video stream). I use os.listdir(path) to get the new files in my iterations. The problem is that when a new .mp4 file is created, first an empty file is created while the contents are being appended incrementally, so the file is not yet finalized/finished/playable (usually if you look at a folder, these files are shown like no extension).
Is it possible to ignore such non-finalized files at the Python level when getting the list of files in directory? Maybe some functions or API exists for that?
Using glob.glob('*.mp4', root_dir=path) should be just fine.
https://docs.python.org/3/library/glob.html

Use Python to compare two folders and all of the files inside

I'm wanting to make a little python script to check and compre the contents of two folders and all the files inside.
Cycle through folder structure based on Folder A
Compare every file from Folder A with Folder B
If the file doesn't exist or the contents is NOT 100% identical then to COPY the file to Folder C but in the same folder structure as Folder A
Could anyone advise on how to do such a feat?
I believe dircmp from filecmp does most of that for you:
https://docs.python.org/2/library/filecmp.html
You can just extend the basic example in this page. By using the attributes left_only, right_only and diff_files you can easily identify missing and not 100% idendical files.

Categories