[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

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

本帖最后由 娜美 于 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 实现
希望能支持尽可能多的有特殊符号文件名称  谢谢

  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

评分人数

TOP

回复 2# went


   大哥哥威武      初步试一下可以  明天再细测一下哈   多谢大哥哥

TOP

返回列表