'unable to iterate through all files present in a folder
# Folder Path
path = "/content/gdrive/MyDrive/data files"
# Change the directory
os.chdir(path)
# Read text File
def read_text_file(file_path):
with open(file_path, 'r') as f:
info=f.read()
stop_words(info)
# iterate through all file
for file in os.listdir():
# Check whether file is in text format or not
if file.endswith(".txt"):
file_path = f"{path}/{file}"
# call read text file function
read_text_file(file_path)
['Impacts COVID 19 Food products - Blackcoffer Insights', '\nSome vendors (fruit vegetable sellers) began venturing days without explicit permission immediately faced police harassment. weeks, government eased restrictions essential vendors were\xa0being permitted vend\xa0(due large part advocacy vendor organizations activist networks). However, cost business, well risk, gone significantly, vendors access wholesale markets suppliers spend travel costs due travel restrictions place city. Also, lockdown still partially place, number buyers gone earnings. Due harsh summer heat, perishable fruits vegetables also reduced shelf life vendors unable capitalize whatever produce have.\nThe state recently announced a\xa0stimulus package INR 5000 crore nearly 50 lakh vendors, acknowledging grave impact loss livelihood. intended relief vendors credit loan provide initial working capital INR 10,000 vendors, sufficient. Instead credit, government think converting direct income benefit, cash grant, livelihood support start income activity regularly. vendors need income support able restart work, able so, return loan. face ever-changing crisis, vendor organizations step forward advocate vendors provided resources need able resume livelihoods. end, vendors organizations could consider following advocacy agenda:\nLivelihood promotion vendors, including selling non-essential goods: impact COVID-19 harsh informal workers exhausted capital earnings trying feed extended lockdown period. Vendors need able resume vending survival government take steps begin reopen markets allow vendors back streets.Reopening Markets keeping mind social distancing hygiene: Delhi many different types traditionally crowded markets including weekly markets (for fresh food, cooked food essential household items) daily markets operate sides roads. markets need resume keeping mind need social distancing government release guidelines same. Going forward, vending zones must also designed keeping mind need social distancing sufficient hygiene facilities (running water, washing stations toilets). authorities work Town Vending Committees (TVCs) same.Provide direct support de-linked existing registration requirements: lockdown lifted vending resumes, vendors home months need direct income benefits resume work. government stimulus package, welcome step, insufficient nature relief (credit direct cash transfer) eligibility (only registered vendors eligible, leaves majority vendors country). addition, government relief support needs de-linked rigid registration requirements, vendors registered India. Delhi, roughly 300,000 street vendors, 131,00 form occupational identification. criteria kind cash grant livelihood support linked occupational identification state, government also accept registration workers’ organisation/union proxy government-issued vending passes.Ensuring hygiene social distancing sites vending: government needs take steps provision running water soap/sanitisers street vendors place work. Additionally, vendor organisations work food safety authorities country train vendors (especially cooked food vendors) ways maintain hygiene working.Taking steps survey register vendors access government benefits: mentioned earlier, number vendors form identification fraction actual population vendors Delhi. crisis subsequent lockdown, Town Vending Committees (TVCs) supposed start surveying registering vendors. get used new normal, process survey registration also begin ensure vendors able access social security benefits financial aid period crisis.\nBlackcoffer Insights 34: Parth Goyal, IET DAVV\n']
Old length: 4884
New length: 3610
['Impacts COVID 19 Food products - Blackcoffer Insights', '\nSome vendors (fruit vegetable sellers) began venturing days without explicit permission immediately faced police harassment. weeks, government eased restrictions essential vendors were\xa0being permitted vend\xa0(due large part advocacy vendor organizations activist networks). However, cost business, well risk, gone significantly, vendors access wholesale markets suppliers spend travel costs due travel restrictions place city. Also, lockdown still partially place, number buyers gone earnings. Due harsh summer heat, perishable fruits vegetables also reduced shelf life vendors unable capitalize whatever produce have.\nThe state recently announced a\xa0stimulus package INR 5000 crore nearly 50 lakh vendors, acknowledging grave impact loss livelihood. intended relief vendors credit loan provide initial working capital INR 10,000 vendors, sufficient. Instead credit, government think converting direct income benefit, cash grant, livelihood support start income activity regularly. vendors need income support able restart work, able so, return loan. face ever-changing crisis, vendor organizations step forward advocate vendors provided resources need able resume livelihoods. end, vendors organizations could consider following advocacy agenda:\nLivelihood promotion vendors, including selling non-essential goods: impact COVID-19 harsh informal workers exhausted capital earnings trying feed extended lockdown period. Vendors need able resume vending survival government take steps begin reopen markets allow vendors back streets.Reopening Markets keeping mind social distancing hygiene: Delhi many different types traditionally crowded markets including weekly markets (for fresh food, cooked food essential household items) daily markets operate sides roads. markets need resume keeping mind need social distancing government release guidelines same. Going forward, vending zones must also designed keeping mind need social distancing sufficient hygiene facilities (running water, washing stations toilets). authorities work Town Vending Committees (TVCs) same.Provide direct support de-linked existing registration requirements: lockdown lifted vending resumes, vendors home months need direct income benefits resume work. government stimulus package, welcome step, insufficient nature relief (credit direct cash transfer) eligibility (only registered vendors eligible, leaves majority vendors country). addition, government relief support needs de-linked rigid registration requirements, vendors registered India. Delhi, roughly 300,000 street vendors, 131,00 form occupational identification. criteria kind cash grant livelihood support linked occupational identification state, government also accept registration workers’ organisation/union proxy government-issued vending passes.Ensuring hygiene social distancing sites vending: government needs take steps provision running water soap/sanitisers street vendors place work. Additionally, vendor organisations work food safety authorities country train vendors (especially cooked food vendors) ways maintain hygiene working.Taking steps survey register vendors access government benefits: mentioned earlier, number vendors form identification fraction actual population vendors Delhi. crisis subsequent lockdown, Town Vending Committees (TVCs) supposed start surveying registering vendors. get used new normal, process survey registration also begin ensure vendors able access social security benefits financial aid period crisis.\nBlackcoffer Insights 34: Parth Goyal, IET DAVV\n']
Old length: 4884
New length: 3610
['Impacts COVID 19 Food products - Blackcoffer Insights', '\nSome vendors (fruit vegetable sellers) began venturing days without explicit permission immediately faced police harassment. weeks, government eased restrictions essential vendors were\xa0being permitted vend\xa0(due large part advocacy vendor organizations activist networks). However, cost business, well risk, gone significantly, vendors access wholesale markets suppliers spend travel costs due travel restrictions place city. Also, lockdown still partially place, number buyers gone earnings. Due harsh summer heat, perishable fruits vegetables also reduced shelf life vendors unable capitalize whatever produce have.\nThe state recently announced a\xa0stimulus package INR 5000 crore nearly 50 lakh vendors, acknowledging grave impact loss livelihood. intended relief vendors credit loan provide initial working capital INR 10,000 vendors, sufficient. Instead credit, government think converting direct income benefit, cash grant, livelihood support start income activity regularly. vendors need income support able restart work, able so, return loan. face ever-changing crisis, vendor organizations step forward advocate vendors provided resources need able resume livelihoods. end, vendors organizations could consider following advocacy agenda:\nLivelihood promotion vendors, including selling non-essential goods: impact COVID-19 harsh informal workers exhausted capital earnings trying feed extended lockdown period. Vendors need able resume vending survival government take steps begin reopen markets allow vendors back streets.Reopening Markets keeping mind social distancing hygiene: Delhi many different types traditionally crowded markets including weekly markets (for fresh food, cooked food essential household items) daily markets operate sides roads. markets need resume keeping mind need social distancing government release guidelines same. Going forward, vending zones must also designed keeping mind need social distancing sufficient hygiene facilities (running water, washing stations toilets). authorities work Town Vending Committees (TVCs) same.Provide direct support de-linked existing registration requirements: lockdown lifted vending resumes, vendors home months need direct income benefits resume work. government stimulus package, welcome step, insufficient nature relief (credit direct cash transfer) eligibility (only registered vendors eligible, leaves majority vendors country). addition, government relief support needs de-linked rigid registration requirements, vendors registered India. Delhi, roughly 300,000 street vendors, 131,00 form occupational identification. criteria kind cash grant livelihood support linked occupational identification state, government also accept registration workers’ organisation/union proxy government-issued vending passes.Ensuring hygiene social distancing sites vending: government needs take steps provision running water soap/sanitisers street vendors place work. Additionally, vendor organisations work food safety authorities country train vendors (especially cooked food vendors) ways maintain hygiene working.Taking steps survey register vendors access government benefits: mentioned earlier, number vendors form identification fraction actual population vendors Delhi. crisis subsequent lockdown, Town Vending Committees (TVCs) supposed start surveying registering vendors. get used new normal, process survey registration also begin ensure vendors able access social security benefits financial aid period crisis.\nBlackcoffer Insights 34: Parth Goyal, IET DAVV\n']
Old length: 4884
New length: 3610
['Impacts COVID 19 Food products - Blackcoffer Insights', '\nSome vendors (fruit vegetable sellers) began venturing days without explicit permission immediately faced police harassment. weeks, government eased restrictions essential vendors were\xa0being permitted vend\xa0(due large part advocacy vendor organizations activist networks). However, cost business, well risk, gone significantly, vendors access wholesale markets suppliers spend travel costs due travel restrictions place city. Also, lockdown still partially place, number buyers gone earnings. Due harsh summer heat, perishable fruits vegetables also reduced shelf life vendors unable capitalize whatever produce have.\nThe state recently announced a\xa0stimulus package INR 5000 crore nearly 50 lakh vendors, acknowledging grave impact loss livelihood. intended relief vendors credit loan provide initial working capital INR 10,000 vendors, sufficient. Instead credit, government think converting direct income benefit, cash grant, livelihood support start income activity regularly. vendors need income support able restart work, able so, return loan. face ever-changing crisis, vendor organizations step forward advocate vendors provided resources need able resume livelihoods. end, vendors organizations could consider following advocacy agenda:\nLivelihood promotion vendors, including selling non-essential goods: impact COVID-19 harsh informal workers exhausted capital earnings trying feed extended lockdown period. Vendors need able resume vending survival government take steps begin reopen markets allow vendors back streets.Reopening Markets keeping mind social distancing hygiene: Delhi many different types traditionally crowded markets including weekly markets (for fresh food, cooked food essential household items) daily markets operate sides roads. markets need resume keeping mind need social distancing government release guidelines same. Going forward, vending zones must also designed keeping mind need social distancing sufficient hygiene facilities (running water, washing stations toilets). authorities work Town Vending Committees (TVCs) same.Provide direct support de-linked existing registration requirements: lockdown lifted vending resumes, vendors home months need direct income benefits resume work. government stimulus package, welcome step, insufficient nature relief (credit direct cash transfer) eligibility (only registered vendors eligible, leaves majority vendors country). addition, government relief support needs de-linked rigid registration requirements, vendors registered India. Delhi, roughly 300,000 street vendors, 131,00 form occupational identification. criteria kind cash grant livelihood support linked occupational identification state, government also accept registration workers’ organisation/union proxy government-issued vending passes.Ensuring hygiene social distancing sites vending: government needs take steps provision running water soap/sanitisers street vendors place work. Additionally, vendor organisations work food safety authorities country train vendors (especially cooked food vendors) ways maintain hygiene working.Taking steps survey register vendors access government benefits: mentioned earlier, number vendors form identification fraction actual population vendors Delhi. crisis subsequent lockdown, Town Vending Committees (TVCs) supposed start surveying registering vendors. get used new normal, process survey registration also begin ensure vendors able access social security benefits financial aid period crisis.\nBlackcoffer Insights 34: Parth Goyal, IET DAVV\n']
Old length: 4884
I am getting the output of the same file repetedly but not of the other files present in the folder . I am unable to figure out what is happening. the code is to read the folder and iterate through all 171 files present in the folder and remove stop words from them .
Solution 1:[1]
You can get the text files list by using glob.glob()
import glob
text_files = glob.glob(path + "/**/*.txt", recursive = True)
for file in text_files:
# Check whether file is in text format or not
read_text_file(file_path)
Hope it could help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | David Lu |