Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------
- EXPLANATION:
- ENGLISH: https://neculaifantanaru.com/en/python-delete-all-files-with-less-than-250-characters.html
- ROMANIAN: https://neculaifantanaru.com/python-sterge-toate-fisierele-cu-mai-putin-de-250-de-caractere.html
- ----------------------
- import os
- import re
- import random
- import unidecode
- import nltk
- from nltk import tokenize
- # nltk.download('punkt')
- import requests
- from usp.tree import sitemap_tree_for_homepage
- def read_text_from_file(file_path):
- """
- Aceasta functie returneaza continutul unui fisier.
- file_path: calea catre fisierul din care vrei sa citesti
- """
- with open(file_path, encoding='utf8') as f:
- text = f.read()
- f.close()
- return text
- FOLDER_LOCAL = 'd:\\Folder1'
- counter_sterse = 0
- for f in os.listdir(FOLDER_LOCAL):
- if f.endswith('.html') or f.endswith('.htm'):
- filepath = os.path.join(FOLDER_LOCAL, f)
- page_html = read_text_from_file(filepath)
- if len(page_html) < 250:
- os.remove(filepath)
- counter_sterse += 1
- continue
- print("S-au sters {} fisiere".format(counter_sterse))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement