473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Re: Windows OS , Bizarre File Pointer Fact

Taygun Kekec wrote:
Code :
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os

if os.name == 'nt':
OS_Selection = 0
elif os.name == 'posix':
OS_Selection = 1
else :
OS_Selection = 1

del_cmd_os = ( "del","rm")
filelist = ("ddd.txt","eee.txt","fff.txt")

# Creating Files
for elem in filelist:
open( elem, 'w').write("Selam")

#
# Removing Files
for elem in filelist:
fp = open( elem, 'r')
os.system( "%s %s" % (del_cmd_os[OS_Selection], fp.name))
fp.close()
#

Run this code on Windows XP , it says "the file is being used by
another process" and fails to delete the file. I tried replacing :
#
for elem in filelist:
open( elem, 'w').write("Selam")
#
with :
#
for elem in filelist:
fp = open( elem, 'w')
fp.write("Selam")
fp.close()
#

in case of any interpreter file pointer destructor failure but it
didnt change anything.
Do you have any idea why my files cannot be deleted from my disk with
2nd part of my code ?
Why are you executing another program just to delete a file?
>>import os
os.remove('some/file.txt')
--
Jun 27 '08 #1
0 668

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alan Little | last post by:
This is very bizarre. Could someone else have a look at this? Maybe you can see something I'm overlooking. Go here: http://www.newsletters.forbes.com/enews/admin/deliver.php4 U: bugtest P:...
12
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I...
1
by: clusardi2k | last post by:
Hello, I have a shared drive on SGI, Linux, and Windows. The fact that I'm using a shared drive may be mute information. The problem is within the same program a second call to fopen does not...
2
by: Garry Freemyer | last post by:
I wrote a screensaver, via Visual Studio 2003 in C# and I decided a wiser choice for me was to use an xml file to save my configs. Btw: I wonder if this is why every bit of documentation I've found...
3
by: Chris Paul | last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows. I've set this up countless times on BSD (piece of cake) but I'm trying to do this on Windows now so that my developer can work...
165
by: Dieter | last post by:
Hi. In the snippet of code below, I'm trying to understand why when the struct dirent ** namelist is declared with "file" scope, I don't have a problem freeing the allocated memory. But...
4
by: reachsamdurai | last post by:
Hello, Can you please let me know the procedure to reach db2 command prompt from a cygwin window (hence without using Start-> Run -> db2cmd method). I'm planning to write shell scripts which...
26
by: the.tarquin | last post by:
Okay, this one has me totally baffled. I have a function, getParsedKey(char* key, char* returnString). I pass in the key I want, it retrieves it from a data structure and puts the value in...
6
by: jojoba | last post by:
Hi, I am trying to create a .net webservice such that: When a user calls the service, the server creates a System.Windows.Forms.Form and shows it on the server screen. I know this sounds...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.