Friday, January 1, 2016

Leveraging python scripts

In the recent past I happened to have assigned a task of Uploading 200K files in total to some cloud app for testing purpose. The challenge was to create that many files, but, thanks to Python robustness that helped me saving myself from laborious and tedious work of creating folders and files within those folders.

Following is the script for that purpose.


========================================================== 
#This script creates total of  200000 Files in 2000 folders 
#i.e each folder e.g MZ_STRESS_1 contains 100 text files
import os

file_list = os.listdir(r"F:\\python_projeects\\Folder_Library")
print(file_list)
current_path = os.getcwd()
print("Current working directory : "+current_path)
os.chdir(r"F:\\python_projeects\\Folder_Library")


for x in range(1,2001):
    os.mkdir(r"MZ_STRESS_"+str(x))
        for y in range(1,101):
            fo = open("F:\\python_projeects\\Folder_Library\MZ_STRESS_"+str(x)+"\\File_"+str(y)+".txt", "wb")
            fo.write(u''+u'\n')
            fo.close()

print("Job finished!!!")

==========================================================
   
Share your snippets you've ever prepared for doing such and similar small tasks using any language.


Happy testing! :-)





       
       

No comments:

Post a Comment