根据文件名称将文件复制到匹配的目标文件夹

根据文件名称将文件复制到匹配的目标文件夹

我有这样的文件。

Makeup_Artists_A_Kreations_Hair_And_Beyond Makeup_Artists_A_Kreations_Hair_And_Beyond1 Makeup_Artists_A_Kreations_Hair_And_Beyond2 Makeup_Artists_A_Kreations_Hair_And_Beyond3 Makeup_Artists_A_Kreations_Hair_And_Beyond4 Makeup_Artists_A_Kreations_Hair_And_Beyond5 Make_Artist_JustinWorks Make_Artist_JustinWorks1 Make_Artist_JustinWorks2

我想将这些文件移动/复制到名为 的文件夹 A_Kreations_Hair_And_BeyondJustinWorks

有任何输入吗/?

注释/提示:我已经准备好了文件夹结构,并且Make Artist适用于所有文件。我厌倦了尝试此网站中的所有输入搜索结果。

谢谢

答案1

Powershell 和批处理解决方案并没有太大区别。进入 Powershell/cmd - 控制台

批:

For %A in ("JustinWorks" "A_Kreations_Hair_And_Beyond"
  ) Do (if not Exist ".\%~A" MD ".\%~A"
    Move ".\*%~A*" ".\%~A\"
)

电源外壳

"JustinWorks", "A_Kreations_Hair_And_Beyond"|
  %{$Name=$_;if (!(Test-Path(".\$_"))) {MD ".\$_"};
    GCI "*$Name*" |%{MV -path "$_" -dest ".\$Name\" -ea silentlycontinue}}

编辑

批处理文件解决方案假设前缀是恒定的,Make_Artist_varBaseFldr必须相应地更改。该命令Move /Y将覆盖子文件夹中已经存在的文件,要求更改为Move /-Y

:: move2Sub.cmd :::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off & setlocal EnableExtensions EnableDelayedExpansion
Set BaseFldr="Q:\Test\2016-11\02"
PushD %BaseFldr% ||(Echo Can't cd to %BaseFldr% & Pause & Goto :eof)
Set "PreFix=Makeup_Artists_"
For /F "delims=" %%A in (
  'Dir /B/ON/A-D "%PreFix%*" ^>Nul 2^>^&1'
    ) Do Call :CheckFile "%%~nxA"
Goto :Eof
:CheckFile "FullName"
If Not Exist %1 Goto :Eof
Set "File=%~n1"
:: remove Prefix
Set "Name=!File:%PreFix%=!"
:: check for trailing number, should already be processed
:Again
Echo:%Name:~-1%|Findstr "[0-9]" >Nul 2>&1 &&(Set "Name=!Name:~0,-1!"&Goto :Again)
If Not Exist "%Name%" MD "%Name%"
Move /Y "%PreFix%%Name%*%~x1" "%Name%" >NUL
Goto :Eof

高血压

相关内容