简体   繁体   English

os.listdir 只显示隐藏文件?

[英]os.listdir only showing hidden file?

Honestly I have no idea what happened because one second this was working as it should and I was testing and made an unrelated change and now it is not.老实说,我不知道发生了什么,因为一秒钟它可以正常工作,我正在测试并进行了无关的更改,但现在不是。 When I run it it only shows a file called '.vs' and none of the actual files in the directory?当我运行它时,它只显示一个名为“.vs”的文件,目录中没有任何实际文件? It is throwing an error saying I don't have permission.它抛出一个错误,说我没有权限。 The directory looks fine in the variable explorer.. it never changes.该目录在变量资源管理器中看起来不错..它永远不会改变。

import pandas as pd
import numpy as np
import pyodbc
from sqlalchemy import create_engine, event
import urllib
import os


directory = r'C:/users/'
print(directory)

for filename in os.listdir(directory):
    print(filename)

this code prints all hidden files from current dictionary此代码打印当前字典中的所有隐藏文件

import os

files = list(os.popen("ls -a")) # on Linux
files = list(os.popen("dir -a")) # on Windows
hidden_files = [hidden.strip() for hidden in files if hidden.startswith(".")][2:]
print(hidden_files)

If you are using windows, go to explorer and right click on the directory then select properties.如果您使用的是 Windows,请转到资源管理器并右键单击目录,然后选择属性。 In the properties window select Security tab.在属性窗口中选择安全选项卡。 The Security window will show groups or user names that have permissions to access the directory and what they are allowed to do. “安全”窗口将显示有权访问目录的组或用户名以及他们可以执行的操作。 If you do not have access click on Edit then click on Add.如果您没有访问权限,请单击编辑,然后单击添加。 You can add Everyone and give full control in permissions.您可以添加“所有人”并完全控制权限。 This should allow full access to the directory.这应该允许完全访问目录。 Not a good thing to do security wise but at least it should allow access.明智地做到安全并不是一件好事,但至少它应该允许访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM