3

I have a python script that builds a file by searching through folders and pulling in a list of files. This file runs fine and works as expected when I open and run it in IDLE, but if when I run the script in a commandline window I get this error:

C:\Windows\system32>python "C:\Users\ntreanor\Documents\RV Scripts\Server RV Sequence.py"
Traceback (most recent call last):
  File "C:\Users\ntreanor\Documents\RV Scripts\Server RV Sequence.py", line 69,
in <module>
    for foldername in os.listdir(pngFolders):
WindowsError: [Error 3] The system cannot find the path specified:
    'Y:/20_temp_script_testing/pr126 movs\\04_comp_pngs/*.*'

In case it's not obvious, yes the path does exist. It not only works in IDLE but I double checked and the path definitely exists.

I also tried to create folders with a script that runs as a daemon and got a similar result

Traceback (most recent call last):
  File "D:\shotgun\shotgunEventDaemon.py", line 888, in process
    self._callback(self._shotgun, self._logger, event, self._args)
  File "D:\shotgun\plugins\CreateAssetFolders.py", line 72, in createAssetFolders
    os.makedirs(folder)
  File "D:\Python27\Lib\os.py", line 150, in makedirs
    makedirs(head, mode)
  File "D:\Python27\Lib\os.py", line 150, in makedirs
    makedirs(head, mode)
  File "D:\Python27\Lib\os.py", line 150, in makedirs
    makedirs(head, mode)
  File "D:\Python27\Lib\os.py", line 157, in makedirs
    mkdir(name, mode)
WindowsError: [Error 3] The system cannot find the path specified: 'Y:/'

This is what the script logged as a folder right before that:

Making folder:
Y:/07_design/04_environmental_elements\eec005-08_insect_ladybird_red_7_spots_wide

(the reason it's saying Y and not the whole path is that it attempts to make each folder back until it can't go back any further and that's when the exception is thrown)

Are the environment variables of the commandline window somehow affecting the drive mapping that should be pointing the script to the right location?

SuperBiasedMan
  • 9,814
  • 10
  • 45
  • 73
  • 1
    Did you notice you have mixed `/` and \ in the filename? – Klaus D. Feb 23 '15 at 12:09
  • The mixing of / and \\ works correctly, athoug use of / is advised if there's the remote chance for the code to ever run on Linux. If you don't do that, the off day you take your code to *NIX you get a mess. Its the * that's giving him trouble. – bconstanzo Feb 23 '15 at 12:38
  • I did, yes. For the moment I'm declaring the base paths literally (since this is just testing) and then using os.path.join to make other folders, so the join method is what put in the '\\'. – SuperBiasedMan Feb 23 '15 at 13:01
  • The only way I could replicate your error msg is trying to open a nonexistent folder, but you say you checked paths and run as admin. Is there something more to know? – bconstanzo Feb 23 '15 at 14:15
  • There probably is, but I guess I'm not aware of it either. I added a check for if the directory exists and it says it doesn't on the commandline, but the IDLE script still runs fine. I'll talk to our IT guy, perhaps there's more unusual permissions surrounding the server that I'm not aware of. – SuperBiasedMan Feb 23 '15 at 14:32
  • Minor update, when I run off another machine (though still not the one I'm trying to access) it runs fine. It's something particular to my set up, whether that's somehow Python or the commandline I still don't know. – SuperBiasedMan Feb 23 '15 at 14:39

2 Answers2

3

The issue is likely because IDLE and your command line are running with a different level of privileges. Mapped network drives are not automatically available to all user contexts. There is a superuser question on this here and plenty of other resources cover this topic. In short, the mapped network drive is only available to programs running at the level the mapping was made at.

If you have mapped the network drive through the windows UI, then it will be mapped for un-elevated programs. However if it was mapped with net use then it depends on the level of the command prompt when the mapping was made!

Disabling UAC will also affect change this behaviour, as will use of an elevated (or not) command prompt, which may explain why some PCs display different behaviour.

Community
  • 1
  • 1
three_pineapples
  • 11,579
  • 5
  • 38
  • 75
  • Thanks for the response, I'll look into it. Do you think there's a way to do this programatically? It would be easier if it could be solved within the script somehow but I realise that may be an unreasonable hope. – SuperBiasedMan Jun 05 '15 at 14:53
  • @SuperBiasedMan Did this end up solving your problem? You can certainly map the network drive programatically. Check out the many answers to [this](http://stackoverflow.com/q/1271317/1994235) question. – three_pineapples Jun 09 '15 at 04:18
  • I had to talk with our IT guy before I could do anything on the server so I haven't actually resolved the problem, but I'll still mark yours as accepted because it's explained the source of the problem, thanks! – SuperBiasedMan Jun 09 '15 at 13:57
-1

I think your problem is that you're trying to open the * file, which of course doesn't exist. open(path) takes path as a literal string and doesn't translate it in anyway, so it expects that value to be a valid filename. You should change your code to get a directory instead of a file, and then walking that directory.

bconstanzo
  • 566
  • 4
  • 10
  • I'm not actually specifying that as a file, I'm using the os.listdir function for a loop, like this: for foldername in os.listdir(folders): – SuperBiasedMan Feb 23 '15 at 12:59