Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python mkdir maakedirs使用与现有文件类似的名称创建目录_Python_Windows_Mkdir_Create Directory - Fatal编程技术网

python mkdir maakedirs使用与现有文件类似的名称创建目录

python mkdir maakedirs使用与现有文件类似的名称创建目录,python,windows,mkdir,create-directory,Python,Windows,Mkdir,Create Directory,我想创建一个名为existing file的目录。在本例中,我有一个名为test的文件,我想创建一个同名的目录。在Linux上,我只能使用os.system(“mkdir”+dir\u name),但在windows上它不起作用。所以我尝试了os.mkdir和os.makedirs如下: import os def my_function(): path = input("Enter dir name or full path.") try: os.mak

我想创建一个名为existing file的目录。在本例中,我有一个名为test的文件,我想创建一个同名的目录。在Linux上,我只能使用os.system(“mkdir”+dir\u name),但在windows上它不起作用。所以我尝试了
os.mkdir
os.makedirs
如下:

import os

def my_function():
    path = input("Enter dir name or full path.")
    try:   
        os.makedirs(path)
    except OSError as e:
        print(e)
os.mkdir
os.makedirs
都给了我一个错误:

[WinError 183]无法创建已存在的文件:“测试”

第一个问题,为什么不能创建文件?我是mkdir。我试图创建目录而不是文件。
第二个问题:同名的文件和目录可以共存。为什么我不能创造它。我如何使它以在Win和Linux上运行的方式运行

在Linux或Windows中,无法在给定目录中创建同名目录和文件。也许在Linux上,您正在一个与您想象的不同的目录中创建它,或者使用不同的外壳。Windows文件系统不区分大小写,因此“dirname”与“dirname”相同。确定。对,我只能在Linux上做。在Windows上它不工作。感谢您在Linux上不能同时拥有名为
/test/test
的文件和目录。这在我使用过的任何操作系统上都不起作用。