Cygwin sees a file that windows can't--I want to access this file from python

泪湿孤枕 提交于 2019-12-30 10:47:06

问题


I have a device connected to my USB that creates a logfile called Tpolling.log. I can see it through Cygwin but I can't see it through Windows (with hidden files set to be always shown). I can't access it from python either.

I want to be able to read it in python but python doesn't find it.

The cygwin path that works is

  /cygdrive/c/Program Files (x86)/TDA

An ls shows that there's a file called Tpolling.log

$ cygpath -w "/cygdrive/c/Program Files (x86)/TDA"
C:\Program Files (x86)\TDA

However, the following gives an error saying no such file as Tpolling.log. I checked the base path with other files.

f= open("C:\\Program Files (x86)\\TDA\\TPolling.log",'r')

Windows can't see the file Tpolling.log when I run "Dir" in command propmpt. The file is saved on the USB device in its flash memory, I did not ask cygwin to mount it so I am not sure how cygwin can see it.

How do I access it from python, apart from running the python program from cygwin?

Here's the files permissions from cygwin-

    drwx------+ 1 SYSTEM         SYSTEM             0 Jul 23 11:27 .
    drwx------+ 1 Administrators None               0 Jul 23 14:39 ..
    -rwx------+ 1 SYSTEM         SYSTEM        684032 Dec 27  2010 NationalInstruments.UI.Design.dll
    -rw
    -rwx------+ 1 SYSTEM         SYSTEM          1078 Jan  3  2010 TDAT.ico
    -rwx------+ 1 lab    Domain Users 2920041 Aug  6 14:50 TPolling.log
    -rwx------+ 1 SYSTEM         SYSTEM         65536 Dec 27  2010 Winsoft.ComPort.dll

回答1:


Windows Application Compatibility to the rescue.

You can find your log file under C:\Users\USERNAME\AppData\Local\VirtualStore\Program Files (x86)\TDA\TPolling.log

For example if you navigate to C:\ you might see the following buttons in explorer:

  • Organize
  • Share with
  • Compatibility files ---> this is your friend, click on it.
  • New folder

What happens in the background that Windows Application Compatibility feature basically simulates the environment (e.g. directories, files, registry keys) for some programs, e.g. for Cygwin and the TDA program. These files are there for programs which need compatibility, but other programs like explorer.exe can't see it.

I thought there is some rootkit on my machine, because I saw files from cygwin but not from explorer. At least it turned out these files are not rootkits, kind of :)




回答2:


dir /a:h will show "hidden" files.

dir /a:s will show "system" files.

If you want to see the file in Windows Explorer, you can uncheck the "Hide protected operating system files" option in the File View options dialog.

You might want to try "dir /a:s >files.txt", and then examining that file to find out if there are any non-visible characters embedded in that filename, and also to see if you have the rights to read / update that file. Otherwise you should be able to open it from Python.




回答3:


Ok, if someone has a similar problem- this is how I solved mine. Huge thanks to Curt and abarnert for helping me get here. I made command prompt behave like cygwin (added cygwin path (c:\cywgin\bin for me) to my path variable ) and then I could just use os.system() to copy the file over from my python program over.



来源:https://stackoverflow.com/questions/18087991/cygwin-sees-a-file-that-windows-cant-i-want-to-access-this-file-from-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!