如何复制或移动具有相同扩展名的多个文件? [英] How to copy or move multiple files with same extension?

查看:44
本文介绍了如何复制或移动具有相同扩展名的多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图将一堆具有类似扩展名的文件从/home/移动到/root/

So I am trying to move a bunch of files with similar extensions from /home/ to /root/

我试过的代码是

file copy /home/*.abc.xyz /root/

也试过了

set infile [glob -nocomplain /home/*.abc.xyz ]
if { [llength $infile] > 0 } { 
    file copy $infile /root/
}

没有成功.

推荐答案

由于不同的原因,您的两次尝试都失败了:

Your two attempts fail for different reasons:

  1. file copy 或任何 Tcl 命令的参数中没有通配符扩展:file copy/home/*.abc.xyz/root/.这将查找文件名中带有文字 * 的单个源.

  1. There is no wildcard expansion in arguments to file copy, or any Tcl command, for that matter: file copy /home/*.abc.xyz /root/. This will look for a single source with a literal * in its filename.

glob -nocomplain/home/*.abc.xyz 可以收集来源,但 glob 返回来源列表.file copy 要求每个源作为单独的参数传递,而不是单个参数.要将源文件的单个集合值扩展为多个单独的参数,请使用 Tcl 扩展运算符 {*}

glob -nocomplain /home/*.abc.xyz is ok to collect the sources, but glob returns a list of sources. file copy requires each source to passed as a separate argument, not a single one. To expand a single collection value of source files into a multiple separate arguments, use the Tcl expansion operator {*}

因此:

set infiles [glob -nocomplain *.tcl]
if {[llength $infiles]} {
   file copy {*}$infiles /tmp/tgt/
}

这篇关于如何复制或移动具有相同扩展名的多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆