Month: April 2016

Python : Script to remove empty directory on your computer

Today, I checked my download folder and found that a lot of empty directories. Because I choose download by JDownloader (open source program to download from http://avxhome.se/).

Sometimes, you can not download all contents that you need and make the computer has a lot of empty directories. Because JDownloader automatically create a folder which contains the download files.

After searching on StackOverFlow, I found a very useful link and modified it so that it suited my situation. Check the script below :

import os
#declare the root directory
root_dir = ‘E:\\Your_download_directory
#initialize the counters
empty_count = 0
used_count = 0
#Set the file to write to, “x” will indicate to create a new file and open it for writting
for curdir, subdirs, files in os.walk(root_dir):
if len(subdirs) == 0 and len(files) == 0:
empty_count += 1 #increment empty_count
print(‘Empty Directory: {}’.format(curdir)) #print the empty directory
os.rmdir(curdir)
print(‘This empty directory was successful removed : {}’.format(curdir))
elif len(subdirs) > 0:
used_count += 1
print(‘Used directory:: {}’.format(curdir)) #print the used directory if you want.
print(‘The total empty directory in this folder : {}’.format(empty_count))

If you check the link below, you will find more useful thing to do with this script.

You can add the result to file and save it like a log file.

Link : Scan files recursively and delete empty directories in python

Reference to os.rmdir : Python os.removedirs() Method

I highly recommend you to only print the result of empty directory first. After that you can uncomment “os.rmdir(curdir)” to delete the result of empty.

Using Python behind the proxy server

Yeah, like the title.

If you are using your computer behind the proxy and you want to write a Python script connect to a website and display a content.

I tried to use socket library but it’s failed and have the error message below :

Untitled

After searching on Google and found a useful link on StackOverFlow website. I change to use urllib2 and I can connect to website through my proxy server.

Untitled1

Actually I allways find solution from this website, thank the guy who created it.

My first programming interview

First of all I finished after work the Ruby Koans, it was an awesome experience and made me understand much more about testing. It happened so fast that I felt sad for being so short but at the same time felt an inner feeling that I have accomplished something good. Rails Tutorial is next (for … Continue reading My first programming interview

https://traintodevelopment.wordpress.com/2016/04/19/my-first-programming-interview/

Practice coding without actually downloading any software

Do you want to try out a new programing language. Then you need to install a lot of components like compiler or interpreter. You can save yourself from installing new components by using online compilers. These compilers only need a computer with a browser that’s it. You can compile and run your code on the […]

https://allfoso.wordpress.com/2016/04/02/practice-coding-without-actually-downloading-any-software/

A map to a first stage of learning python — the_TRAVELLER_is_the_JOURNEY

The atlas is filled with maps, and the roads twist and turn around short-cuts and panoramic views. Here is the advice of a singular traveller, still a beginner. Where this begins This begins where I did. Knowing about programming, and knowing a little about how to program. About 7 years ago I had self-taught a […]

via A map to a first stage of learning python — the_TRAVELLER_is_the_JOURNEY

Não bộ, động lực làm việc, và các “công tắc” kích thích động lực làm việc

Đọc xong cuốn “のうだま―やる気の秘密” (tạm dịch là bí quyết tạo động lực bằng đánh lừa bộ não: http://tinyurl.com/ycmmsx5) của tác giả Ikegaya Yuji (http://www.hippocampus.jp/CV/) – một nhà nghiên cứu về não bộ. Có mấy điểm tóm lược rút ra từ cuốn sách. – Tính “chóng chán” là đặc tính mà ai cũng có vì đây […]

https://khmt.wordpress.com/2015/08/19/nao-bo-dong-luc-lam-viec-va-cac-cong-tac-kich-thich-dong-luc-lam-viec/