【问题标题】:Copy all files from a folder to another one将文件夹中的所有文件复制到另一个文件夹
【发布时间】:2019-02-15 23:08:04
【问题描述】:

我想将一个文件夹中的所有文件复制到 Stata 中的另一个文件夹。

我使用了以下代码:

local dlist: dir "$dir" dirs "*"

foreach d of local dlist {

    local file: dir "$dir\"`d'"" files "*.dta"
    foreach f of local file{
       copy `f' "$dir/PROGRAMMATION/INITIALES"
    }   
}

但是,Stata 返回:

无效语法

$dir 是这个 do-file 所在的实际目录。

【问题讨论】:

  • 我个人只会使用 OS 命令。

标签: copy directory stata


【解决方案1】:

以下对我有用:

global dir /Users/monkey/Downloads

local dlist: dir "$dir" dir "*"

foreach d of local dlist {
    local file: dir "$dir/`d'" files "*.dta"

    foreach f of local file {
       copy "$dir/`d'/`f'"  "/Users/monkey/testdir/`f'"
    }
}   

请注意,代码会将copy/Users/monkey/Downloads每个子目录 中包含的所有 Stata 数据集文件/Users/monkey/testdir/ 复制到目录/Users/monkey/testdir/

如果你只想copy/Users/monkey/Downloads/Users/monkey/testdir/的所有Stata数据集文件,一个循环就足够了:

global dir /Users/monkey/Downloads

local file: dir "$dir" files "*.dta"

foreach f of local file{
    copy "$dir`f'"  "/Users/monkey/testdir/`f'"
}

【讨论】:

  • 您的代码按预期完美运行。其实我已经忘记在复制命令中添加路径了。
猜你喜欢
  • 1970-01-01
  • 2015-01-20
  • 2014-09-17
  • 2016-10-25
  • 2022-01-13
  • 2011-12-19
  • 2018-10-05
  • 1970-01-01
  • 2011-07-19
相关资源
最近更新 更多