Windows目录名称无效

时间:2018-06-26 07:16:42

标签: python python-3.x command-line

这是我正在尝试的代码,但它不断重复相同的错误。 如果我做错了,请告诉我。

import os
import sys

for x in sys.argv:
    for ff in os.listdir(x):
        path = os.path.join(x, ff)
        if os.path.isdir(path):
            print('\n--' + path)
        else:
            print('\t------' + path)

这是不断重复的错误,请有人帮助我。

Traceback (most recent call last):
  File "E:/projects/Intern/file&folders/cc.py", line 5, in <module>
    for ff in os.listdir(x):
NotADirectoryError: [WinError 267] The directory name is invalid: 'E:/projects/Intern/file&folders/cc.py'

3 个答案:

答案 0 :(得分:5)

使用以下代码:-

[root@cuatlrgcprpt01 ~]# kubectl get nodes
NAME             STATUS    ROLES     AGE       VERSION
cuatlrgcprpt01   Ready     master    2h        v1.10.4
cuatlrgcprpt02   Ready     <none>    2h        v1.10.4

[root@cuatlrgcprpt01 ~]# kubectl get services --all-namespaces
NAMESPACE     NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
default       kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP         2h
default       my-nginx     NodePort    10.110.97.191   <none>        80:30080/TCP    15m
kube-system   kube-dns     ClusterIP   10.96.0.10      <none>        53/UDP,53/TCP   2h

[root@cuatlrgcprpt01 ~]# kubectl get pods --all-namespaces  -o wide
NAMESPACE     NAME                                     READY     STATUS    RESTARTS   AGE       IP             NODE
default       my-nginx-77f56b88c8-97n4x                1/1       Running   0          1m        172.17.0.3     cuatlrgcprpt02
default       my-nginx-77f56b88c8-zqc5x                1/1       Running   0          1m        172.17.0.2     cuatlrgcprpt02
kube-system   etcd-cuatlrgcprpt01                      1/1       Running   0          2h        172.30.80.51   cuatlrgcprpt01
kube-system   kube-apiserver-cuatlrgcprpt01            1/1       Running   0          2h        172.30.80.51   cuatlrgcprpt01
kube-system   kube-controller-manager-cuatlrgcprpt01   1/1       Running   0          2h        172.30.80.51   cuatlrgcprpt01
kube-system   kube-dns-86f4d74b45-vd5zp                3/3       Running   0          2h        172.17.0.2     cuatlrgcprpt01
kube-system   kube-proxy-9k555                         1/1       Running   0          2h        172.30.80.51   cuatlrgcprpt01
kube-system   kube-proxy-n24br                         1/1       Running   0          2h        172.30.80.52   cuatlrgcprpt02
kube-system   kube-scheduler-cuatlrgcprpt01            1/1       Running   0          2h        172.30.80.51   cuatlrgcprpt01

您正在将整个import os import sys for x in sys.argv[1:]: for ff in os.listdir(x): path = os.path.join(x, ff) if os.path.isdir(path): print('\n--' + path) else: print('\t------' + path) 列表传递给sys.argv函数。第一个元素始终是脚本本身,而不是目录。因此,我们将参数列表按第一个元素切成薄片。

答案 1 :(得分:0)

几年前,我在Windows计算机上遇到了类似的错误。我认为问题在于您的路径包含特殊字符(&)...只需更改文件夹的名称或使用退格键将其转义

答案 2 :(得分:0)

我认为问题可能在于某些路径包含不受很好支持的字符&
尝试更改该文件夹名称并避免使用此类字符,或者尝试跳过可能包含该文件夹名称的路径。