返回列表 发帖

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

本帖最后由 娜美 于 2022-4-27 17:46 编辑

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

b.txt

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




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

发现不支持某些符号   中文符号 及空格  所以绐出几个示咧文件名称    希望用powershell  bat 实现
希望能支持尽可能多的有特殊符号文件名称  谢谢

#&cls&@cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Out-String | Invoke-Expression " & pause&exit
cls
#变量设置
$txt_file = 'b.txt'
$src_dir = 'D:\A\rar'
$dest_dir = 'D:\123'
New-Item -ItemType Directory -Path @($src_dir,$dest_dir) -ErrorAction SilentlyContinue
#读取列表
$tag_arr = Get-Content -Path $txt_file -Encoding UTF8
#移动
Get-ChildItem -Path $src_dir | Where-Object { !$_.PsIsContainer -and $tag_arr -contains $_.Name } | foreach {
    Move-Item -LiteralPath $_.FullName -Destination $dest_dir
}COPY
1

评分人数

TOP

回复 2# went


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

TOP

返回列表