Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #18291

Re: [Windows 7, Python 2.6] Can't write to a directory made w/ os.makedirs

Date 2012-01-01 09:37 +0000
From Tim Golden <mail@timgolden.me.uk>
Subject Re: [Windows 7, Python 2.6] Can't write to a directory made w/ os.makedirs
References <50693cc2-93c9-481d-9fb1-42312e69b2d9@c42g2000prb.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4289.1325410678.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 31/12/2011 22:13, OlyDLG wrote:
 > Hi!  I'm working on a script utilizing os.makedirs to make directories
 > to which I'm then trying to write files created by exe's spawned w/
 > subprocess.call; I'm developing in Stani's Python Editor, debugging
 > using Winpdb.  I've gotten to the point where
 > subprocess.Popen._execute_child is raising a WindowsError(5,'Access is
 > denied') exception.  I've tried: setting the mode in the makedirs
 > call; using os.chmod(<dir>, stat.S_IWRITE); and even setting a
 > breakpoint before the subprocess.call and unsetting the read-only
 > attribute of the pertinent directory tree using the Windows directory
 > Properties dialog--which doesn't "take," if that's a clue--all to no
 > avail.

Whatever you're trying to do, resetting the read-only bit
on the Windows directory is not the answer. It has, bizarrely,
nothing to do with the read/write-ness of a directory; rather,
it reflects the system-ness of a folder.

There's no general answer I can see to give, without
knowing what the security is on your folders or what
other thing might impede your processes from writing
files in them. Is it definite that the ERROR_ACCESS_DENIED
is in fact the result of attempting to write a file into
one of the newly-created directories?

Can you do something like this (adapt for your own environment):

<code>
import os, sys
import subprocess

os.makedirs ("c:/temp/a/b/c")

with open ("c:/temp/a/b/c/test1.txt", "w"):
   pass

subprocess.call ([
   sys.executable,
   "-c",
   "open ('c:/temp/a/b/c/test2.txt', 'w').close ()"
])

</code>

ie can the Python process creating the directories,
and a subprocess called from it create a simple file?

Depending on where you are in the filesystem, it may indeed
be necessary to be running as administrator. But don't try
to crack every security nut with an elevated sledgehammer.


TJG

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[Windows 7, Python 2.6] Can't write to a directory made w/ os.makedirs OlyDLG <d.l.goldsmith@gmail.com> - 2011-12-31 14:13 -0800
  Re: [Windows 7, Python 2.6] Can't write to a directory made w/ os.makedirs Tim Golden <mail@timgolden.me.uk> - 2012-01-01 09:37 +0000
    Re: Can't write to a directory made w/ os.makedirs David Goldsmith <eulergaussriemann@gmail.com> - 2012-01-01 04:05 -0800
      Re: Can't write to a directory made w/ os.makedirs Tim Golden <mail@timgolden.me.uk> - 2012-01-01 15:05 +0000
        Re: Can't write to a directory made w/ os.makedirs David Goldsmith <eulergaussriemann@gmail.com> - 2012-01-01 19:14 -0800
          Re: Can't write to a directory made w/ os.makedirs MRAB <python@mrabarnett.plus.com> - 2012-01-02 03:43 +0000
            Re: Can't write to a directory made w/ os.makedirs David Goldsmith <eulergaussriemann@gmail.com> - 2012-01-03 07:17 -0800
          Re: Can't write to a directory made w/ os.makedirs Tim Golden <mail@timgolden.me.uk> - 2012-01-02 11:11 +0000
          Re: Can't write to a directory made w/ os.makedirs Dave Angel <d@davea.name> - 2012-01-02 09:09 -0500
            Re: Can't write to a directory made w/ os.makedirs David Goldsmith <eulergaussriemann@gmail.com> - 2012-01-02 18:34 -0800

csiph-web