Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52581
| Date | 2013-08-16 11:51 +0530 |
|---|---|
| Subject | How to I do this in Python ? |
| From | Ganesh Pal <ganesh1pal@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.614.1376636762.1251.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
How to I do this in Python ? Ganesh Pal <ganesh1pal@gmail.com> - 2013-08-16 11:51 +0530
Re: How to I do this in Python ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-16 10:59 +0000
Re: How to I do this in Python ? Ganesh Pal <ganesh1pal@gmail.com> - 2013-08-18 22:36 +0530
Re: How to I do this in Python ? Steven D'Aprano <steve@pearwood.info> - 2013-08-19 07:27 +0000
Re: How to I do this in Python ? Ganesh Pal <ganesh1pal@gmail.com> - 2013-08-28 10:10 +0530
Re: How to I do this in Python ? Roy Smith <roy@panix.com> - 2013-08-16 07:47 -0400
Re: How to I do this in Python ? random832@fastmail.us - 2013-08-16 14:17 -0400
csiph-web