找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 13455|回复: 2

[问题求助] poweshell 按需要移动文件

[复制链接]
发表于 2022-4-27 17:44:10 | 显示全部楼层 |阅读模式
本帖最后由 娜美 于 2022-4-27 17:46 编辑

#@&cls&powershell "type %~s0|out-string|iex"&pause&exit

b.txt

  1. 新`新n 建-文-本_ (文 .档 )~!;',@ #$ % ^.& ()_ += -{}[].rar
  2. 新n建-文-本_(文.档)d  afb.rar
  3. 新建(文-)本_文 档xsda+fb.rar
  4. 新建文-本_文 档xs daxfb.rar
复制代码




想按b.txt文本内的文件名, 把D:\A\rar文件移动到D:\123文件夹下      是按b.txt文本名称移动   不是所有都移走噢

发现不支持某些符号   中文符号 及空格  所以绐出几个示咧文件名称    希望用powershell  bat 实现
希望能支持尽可能多的有特殊符号文件名称  谢谢
发表于 2022-4-27 22:04:06 | 显示全部楼层
  1. #&cls&@cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Out-String | Invoke-Expression " & pause&exit
  2. cls
  3. #变量设置
  4. $txt_file = 'b.txt'
  5. $src_dir = 'D:\A\rar'
  6. $dest_dir = 'D:\123'
  7. New-Item -ItemType Directory -Path @($src_dir,$dest_dir) -ErrorAction SilentlyContinue
  8. #读取列表
  9. $tag_arr = Get-Content -Path $txt_file -Encoding UTF8
  10. #移动
  11. Get-ChildItem -Path $src_dir | Where-Object { !$_.PsIsContainer -and $tag_arr -contains $_.Name } | foreach {
  12.     Move-Item -LiteralPath $_.FullName -Destination $dest_dir
  13. }
复制代码

评分

参与人数 1技术 +1 收起 理由
娜美 + 1 thanks

查看全部评分

 楼主| 发表于 2022-4-27 22:48:43 | 显示全部楼层
回复 2# went


   大哥哥威武      初步试一下可以  明天再细测一下哈   多谢大哥哥
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 04:11 , Processed in 0.017825 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表