How to I do this in Python ?

Ganesh Pal ganesh1pal at gmail.com
Fri Aug 16 02:21:32 EDT 2013


Hello  Friends ,

Iam a newbie to python , Iam writing a small script that would generate
various kinds of files
in the specified path . Iam using sub process module to achieve this , I
have stuck with few basic problems , any help on this would be great

Case (a) :

The below code creates the  only one spare file named sp1 ,

 # Creating sparse files in the sparse path
     sparse_path = os.path.join(path,'sparsefiles')
     os.makedirs(sparse_path)
     os.chdir(sparse_path)
     sparsefiles = "dd if=/dev/zero of=sp1 count=0 bs=1 seek=10G"
     process_0 = subprocess.Popen(sparsefiles, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)

Current output :
Sp1,

How do I  loop my script to create 100 of files  like sp1 , sp2 ,sp3,..
sp100  .. using the same syntax
 " sparsefiles = "dd if=/dev/zero of=sp1 count=0 bs=1 seek=10G "


Case (2) :

Is there a better way to create the files in Python other than using  sub
process module and running dd command as shown below ..

Example :

# creating sparse File
 sparse_path = os.path.join(path,'sparsefiles')
     os.makedirs(sparse_path)
     os.chdir(sparse_path)
     sparsefiles = "dd if=/dev/zero of=sp1 count=0 bs=1 seek=10G"
     process_0 = subprocess.Popen(sparsefiles, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)

    # Creating Regular files
     Regular_path = os.path.join(path,'regularfiles')
     os.makedirs(Regular_path)
     os.chdir(Regular_path)
     regularfiles = " dd if=/dev/urandom of=file1 count=0 bs=1 seek=10"
     process_1 = subprocess.Popen(regularfiles, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)


My goal is to create various kinds of files like sparse, regular
,directories, hard and symlinks etc
what would be the best way to do achieve this ?

Regards,
Ganesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130816/a94ef1da/attachment.html>


More information about the Python-list mailing list