0

here is snippet:

p = r"\\server\folder1\folder2"
print p
files = os.listdir(p)
print "found files: ", len(files)

The output on 32bit machine:

\\server\folder1\folder2
found files: 9818

The output on 64bit machine:

\\server\folder1\folder2
found files: 9818

or

\\server\folder1\folder2
<type 'exceptions.WindowsError'> [Error 24] The program issued a command but the command length is incorrect: '\\\\server\\folder1\\folder2/*.*'

I have tried - Python 2.5, 2.7, 32bit and also 64bit (on 64bit machines). - machines are 32bit and 64bit.

The network share is accessible and I have read/write rights.

Any one knows why the error is raised only on 64bit machine???

thx, r

compling
  • 1
  • 1
  • Perhaps the system call status code will be more helpful. Install the [Debugging Tools for Windows](https://msdn.microsoft.com/en-us/library/ff551063). Set a system environment variable for debug symbols: `_NT_SYMBOL_PATH=symsrv*symsrv.dll*C:\Symbols*http://msdl.microsoft.com/download/symbols`. Run your script with `-i`. Attach to python.exe in the debugger. Set a breakpoint on the system call: `bp ntdll!NtQueryDirectoryFile; g`. In Python, call `os.listdir(p)`. In the debugger enter `pt; r rax` to step to the function return and print the status code. Enter `g` to continue. – Eryk Sun Aug 26 '15 at 23:08
  • thx! I will give a try. – compling Aug 28 '15 at 10:02
  • You could also try the following without having to use a debugger. Initial setup: `import ctypes;` `ntdll = ctypes.WinDLL('ntdll');` `ntdll.RtlGetLastNtStatus.restype = ctypes.c_uint`. Then in an `except` block handling the exception you can set `ntstatus = hex(ntdll.RtlGetLastNtStatus())`. – Eryk Sun Aug 28 '15 at 10:09

1 Answers1

0

Try this code it is working on 64 bit machine

import os
p = r"server/folder1"
print p
files = os.listdir(p)
print "found files: ", len(files)
Himanshu dua
  • 2,496
  • 1
  • 20
  • 27
  • Thank you! but still same error - WindowsError: [Error 24] The program issued a command but the command length is incorrect: '//server/folder1/folder2/*.*' – compling Aug 28 '15 at 09:59
  • I have tried this: http://stackoverflow.com/questions/14354113/retrieving-contents-from-a-directory-on-a-network-drive-windows Now I get the error sometimes... I use \\server/folder1/folder2 - could that latency problems? connection issues... – compling Aug 28 '15 at 10:29
  • @compling the path in your example, `r"\\server\folder1\folder2"`, is correct and the canonical form of a UNC path. – Eryk Sun Aug 29 '15 at 03:22
  • what path are you providing as input? – Himanshu dua Aug 31 '15 at 07:52
  • @himanshudua I have tried already combinations r"\\server\folder1\folder2", r"\\server/folder1/folder2", "\\\\server\\folder1\\folder2", "\\\\server/folder1/folder2", and so on... Also tried on different computers (win64), the error is mystic - if once it works, next time it does not... – compling Aug 31 '15 at 10:02
  • @compling Check out the new code its working on my 64 bit windows 8 machine – Himanshu dua Aug 31 '15 at 10:26
  • @compling try r"server/folder1" – Himanshu dua Sep 01 '15 at 05:33
  • @himanshudua THX! indeed I overlooked missing slashes. So now tried r"server/folder1/folder2" and r"/server/folder1/folder2" - both no luck -> Error 3: system can not find path – compling Sep 02 '15 at 09:45