d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Read A Folder And All Sub-folders And Delete Files > Javascript Or Python: 500fg
Add Reply New Topic New Poll
Member
Posts: 14,925
Joined: Jan 3 2008
Gold: 135,879.75
Mar 5 2020 03:41pm
* If the size of the file is less than 5bytes, delete it.

Pm me if any questions about the task.

Please post your code in this thread.

Thanks.
Member
Posts: 12,703
Joined: May 17 2013
Gold: 12,935.00
Mar 8 2020 04:06pm
Code
import os

pathtocheck = 'path_of_folder_to_check'

for (dirpath, dirnames, filenames) in os.walk(pathtocheck):
for filename in filenames:
path = os.path.join(dirpath, filename)
if os.path.getsize(path) <= 5:
print(f'removed {path}')
os.remove(path)


Banned
Posts: 3
Joined: Apr 6 2020
Gold: 0.00
Apr 7 2020 06:50pm
Quote (Klexmoo @ Mar 9 2020 12:06am)
Code
import os

pathtocheck = 'path_of_folder_to_check'

for (dirpath, dirnames, filenames) in os.walk(pathtocheck):
for filename in filenames:
path = os.path.join(dirpath, filename)
if os.path.getsize(path) <= 5:
print(f'removed {path}')
os.remove(path)


^^
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll