0

I have files like this.

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

I wanted to move/copy this files to folder named. A_Kreations_Hair_And_Beyond and JustinWorks.

Any inputs/ ?

Notes/Tips: I have folder structure ready and Make Artist is common in all files. I am tired of trying all the inputs search result in this site.

thanks

  • Frankly speaking, I didn't get similar Question on this site. but i found this one stackoverflow.com/questions/2609776/…. but its perl. I am not much it BATCH, SHELL. I am GIS Guy ;-) – user1586957 Oct 29 '16 at 8:35
  • SuperUser is not a "do my work for me" site and your profile shows some programming knowledge (on StackOverflow). If you tell us what you've tried and where you're stuck we can try to help. – Atzmon Oct 29 '16 at 8:56
  • Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?. – DavidPostill Oct 29 '16 at 10:18
2

Powershell and batch solutions aren't so different. Past into Powershell/cmd - console

Batch:

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

Powershell

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

Edit

A batch file solution assuming the PreFix is constantly Make_Artist_ The var BaseFldrhas to be changed accordingly. The command Move /Y will overwrite files already present in the subfolder, to be asked change to 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

HTH

| improve this answer | |
  • How to make variable "JustinWorks" and "A_Kreations_Hair_And_Beyond" as variable? – user1586957 Nov 2 '16 at 5:11
  • Do you have a list/collection/array of Names to process Which type of script would you use PoSh/batch or any high level language? – LotPings Nov 2 '16 at 11:44
  • I think it should split by "Makeup_Artists_" take the value after this string."Makeup_Artists_" is common pattern in all files names. – user1586957 Nov 2 '16 at 12:13
  • 1
    What about Make_Artist_ and how to treat the trailing numbers? Your question is IMO off topic at this site see Help Center Asking. Changing the question under way is also a nogo. Neverless I'll refine my answer if I get some time – LotPings Nov 2 '16 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.