Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.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将符合条件的文件从一个目录传输到另一个目录_Python_Unix - Fatal编程技术网

使用python将符合条件的文件从一个目录传输到另一个目录

使用python将符合条件的文件从一个目录传输到另一个目录,python,unix,Python,Unix,如果文件名符合特定条件,我需要使用python将文件从UNIX中的一个目录移动/复制到另一个目录,例如filename1=extra_filename2。 我已经准备了下面的脚本,但它给出了错误。 有人能纠正我吗 #!/usr/bin/python import shutil, fnmatch, os for filename in os.listdir('/home/root/Desktop/'): try: file1 = fnmatch.f

如果文件名符合特定条件,我需要使用python将文件从UNIX中的一个目录移动/复制到另一个目录,例如filename1=extra_filename2。 我已经准备了下面的脚本,但它给出了错误。 有人能纠正我吗

#!/usr/bin/python
import shutil, fnmatch, os

for filename in os.listdir('/home/root/Desktop/'):
        try:
                file1 = fnmatch.fnmatch(filename, '*.txt')
                file2 = fnmatch.fnmatch(filename, '*.txt')

        if file1 = extra_'file2'
                print "True"

shutil.copy2('/home/root/Desktop/file1','/home/root/Desktop/Archive',follow_symlinks=True)

谢谢你们的回复,很抱歉我不能表达我的疑问,我只是提供了一个原始代码,这是绝对错误的。 基本上,我是在寻找以下内容:

# 导入操作系统 进口舒蒂尔 进口稀土

源=(“源路径”)

files=os.listdir(源)

对于文件中的名称: 完整路径=源+“/”+名称 Name2=name+“filename2” #打印完整路径 如果在文件中重新匹配(“filename regex”,name)和Name2:

            #shutil.rmtree("destinationPath"+name)
            shutil.copytree(fullpath, "destinationpath"+name)
            shutil.copytree(fullpath, "destinationpath"+Name2)
打印“已完成”


#这有太多的错误…“给出错误”-这是没有帮助的。什么错误?堆栈跟踪是什么?发生了什么事?你期望发生什么事?@Andy我打赌他们中的很多人都是关于
if
这一行的——这段代码甚至不会编译。@Two Bitalchest我在那一行也算了很多东西
=
vs
=
,一个未定义的
额外变量,在语句末尾没有
,没有运算符的串联。我在那条线上错过了什么吗?
            #shutil.rmtree("destinationPath"+name)
            shutil.copytree(fullpath, "destinationpath"+name)
            shutil.copytree(fullpath, "destinationpath"+Name2)