I couldn't find this with a search, but isn't there a way to overwrite
a previous folder (or at least not perform osmkdir( ) if your program
detects it already exists). Thanks ! 6 10824
Ernesto wrote: I couldn't find this with a search, but isn't there a way to overwrite a previous folder (or at least not perform osmkdir( ) if your program detects it already exists). Thanks !
I suppose this also leads to the question of:
"Is there a way to determine if a path exists or not?" Then I could
do:
if(path exists){}
else{mkdir("")}
NEVERMIND ! Here is the solution...
# ----------------------------------------------------------------
if (os.path.isdir( "C:\\MyNewFolde r") == 0):
os.mkdir("C:\\M yNewFolder")
# -----------------------------------------------------------------
thanks
try os.path.exists( path)
-Larry Bates
Ernesto wrote: Ernesto wrote: I couldn't find this with a search, but isn't there a way to overwrite a previous folder (or at least not perform osmkdir( ) if your program detects it already exists). Thanks !
I suppose this also leads to the question of:
"Is there a way to determine if a path exists or not?" Then I could do:
if(path exists){} else{mkdir("")}
Ernesto wrote: I couldn't find this with a search, but isn't there a way to overwrite a previous folder (or at least not perform osmkdir( ) if your program detects it already exists). Thanks !
Would something like this help?
import os
def failsafe_mkdir( dirname):
try: os.mkdir(dirnam e)
except: return False
else: return True
if __name__ == "__main__":
dirname = 'adir'
if failsafe_mkdir( dirname):
print "ok\n"
else:
print "couldn't create %s\n" % dirname
The corect way is to try os.mkdir, catch the exception and check the
errno value, which tell you why the call failed.
If the directory exists, you can ignore the exception, if its another
error, you usually had to raise it again and let the caller handle it.
Example:
import errno
try:
os.mkdir(path)
except OSError, err:
if err.errno != errno.EEXIST:
raise
Any other way may have race conditions, for example, you check if the
directory exits, and its missing, then another process or thread
creates it before you try to create the missing directory, and your
mkdir call will raise.
Ernesto <er*******@gmai l.com> wrote: NEVERMIND ! Here is the solution...
# ---------------------------------------------------------------- if (os.path.isdir( "C:\\MyNewFolde r") == 0): os.mkdir("C:\\M yNewFolder") # -----------------------------------------------------------------
Maybe some other process creates C:\\MyNewFolder between the call of
isdir and mkdir, or mkdir fails for some other reasons (e.g. no
permission), so you have to catch exceptions anyway. But then there's no
need for isdir.
Florian
--
Das ist ja das positive am usenet: man erfährt oft Dinge, nach denen
gar nicht gefragt wurde.
[Konrad Wilhelm in <ls************ *************** *****@4ax.com>] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: christopher vogt |
last post by:
Hi there,
thats an error i try to solve for quite a while already but didn't find a
solution yet.
My problem: I'm writing a little cms, that should create a folderstructure,
so that you can put files in via ftp.
My script (simplified):
mkdir("00000031",0777); // creates a folder named with the id of a
database-record e.g. 00000031
|
by: Alf Laue |
last post by:
Hi,
how do I delete a folder at my ftp-server, that was automatically
created through a installation script? I dont have the permission to
delete that folder :-(
Thx for your help
Alf
|
by: Jon Maz |
last post by:
Hi there,
I am experimenting with the FileSystemWatcher object. I have set the
NotifyFilter as follows:
myFileSystemWatcher.NotifyFilter = NotifyFilters.Security |
NotifyFilters.CreationTime |
NotifyFilters.LastWrite |
NotifyFilters.Size |
NotifyFilters.Attributes |
|
by: Stan |
last post by:
My project folder path is c:\Projects\FinWeb. I set up FinWeb virtual folder
in IIS and pointed it to that path. I can access the web site via
http://localhost/FinWeb.
However, when I try to add FinWeb web project to a solution by using Add
Existing Project from Web, the project isn't there (not under localhost). I
can point to c:\projects\FinWeb and add the project this way and everything
works fine, but when the solution is opened...
|
by: Philip Wagenaar |
last post by:
Hello,
I am writing an application that processes xml files that are stored in a
folder. The application picks up the files in a folder, processes them and
then deletes them.
What is the best approach on loading the xml files from the folder into my
application?
At the moment I am using the System.IO.FileSystemWatcher to monitor files
| |
by: gunaseelan_wipro |
last post by:
Hi all,
In one of my perl scripts when i try to create a directory using mkdir (), the directory is created but the return code for the mkdir () is 512, the same is the case for copy command.
Eg:
my $val = /xyz/abc/dkd
mkdir ($val);
rc = $?
|
by: Natti |
last post by:
Hello,
I am trying to update the STDOUT dynamically.
For eg. I am trying to display a counter whose value should get updated int he same place,
#!/usr/bin/perl
$val = 10;
for ($i=0;$i<=$val;$i+) {
print "$val\n";
}
|
by: 1333 |
last post by:
I need to create a new folder every time the upload folder has 10 files uploaded to it. So when folder1 has 10 files, folder2 is created and becomes the upload folder, and when it has 10 files uploaded to it folder3 is created and so on.....
Problem is that my code creates all the next folders all at once. I need it to create the next folder when it is required. i.e. when the previous folder has reached 10 files.
If anyone can explain...
|
by: B |
last post by:
Hi,
I am using mkdir to create a directory and upload files to it.
Unfortunately the folder is accessible via the url to any user, which
is creating problems. How can I manage permissions with mkdir so the
folder is not availabe via the url path
thanks :)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |