Board logo

标题: [问题求助] PowerShell的copy-item复制文件怎样自动创建文件夹? [打印本页]

作者: 小白龙    时间: 5 天前 17:51     标题: PowerShell的copy-item复制文件怎样自动创建文件夹?

powershell的这个copy-item命令好像有点弱智, 当目标文件夹不存在时不会自动创建文件夹, 我记得在哪里看到过有人就在一行中, 添加了自动创建文件夹的代码, 有人知道怎么写吗? 多谢

下面这样写, 当798文件夹不存在时, 就会报错,
  1. Copy-Item D:\LB\icons.db, D:\LA\otherfile.txt -Destination "$home\desktop\798\" -Force
复制代码

作者: idwma    时间: 5 天前 19:58

本帖最后由 idwma 于 2024-9-16 20:06 编辑
  1. Copy-Item D:\LB\icons.db, D:\LA\otherfile.txt -Destination ("$home\desktop\798\"|%{mkdir $_ 2>&1 1>$null;$_}) -Force
复制代码

作者: 小白龙    时间: 5 天前 20:47

本帖最后由 小白龙 于 2024-9-16 20:49 编辑

回复 2# idwma

下面这样也可以
  1. cp C:\LB\icons.txt, D:\LA\Au.xe (md $home\desktop\798\asd -f) -fo
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2