I'm trying to make a simple Windows batch file to move completed folders based on if they contain a string in the path, I tried messing around with it but I'm sure I'm just doing something stupid and would appreciate some help.
What I am trying to use is a simple line like
cd %1 if exist *string* move %1 E:\folder
but it gives me an error that the syntax is incorrect
Help with creating a move script
-
- Newbie
- Posts: 2
- Joined: May 1st, 2016, 6:54 pm
Re: Help with creating a move script
from the top of my head you would want something like the following in your batch file :
for /f "tokens=*" %%a in ('dir d:\source\*searchterm* /b/a:d') do move d:\source\%%a d:\destination\
replace searchterm with the string you are looking for.. d:\source\ and d:\destination of course with the appropriate directories
be sure to use quotes if there's a chance of a space being in your searchterm
the /b/a:d behind dir means nothing more than :
/b : bare output, so only the file/directoryname including a possible extension
/a:d : only process directories
for /f "tokens=*" %%a in ('dir d:\source\*searchterm* /b/a:d') do move d:\source\%%a d:\destination\
replace searchterm with the string you are looking for.. d:\source\ and d:\destination of course with the appropriate directories
be sure to use quotes if there's a chance of a space being in your searchterm
the /b/a:d behind dir means nothing more than :
/b : bare output, so only the file/directoryname including a possible extension
/a:d : only process directories
-
- Newbie
- Posts: 2
- Joined: May 1st, 2016, 6:54 pm
Re: Help with creating a move script
maybe not the nicest readable .. what was I thinking.. there's the /D switch as well.. sorry I'm a bit tired :-)
above does work, but it's not the shortest, nicest, and lotsa tokens and switches to think of :
Even tested it for you and :
[ Orion@Oldskool-Desktop ] at 02-05-2016 - 2:55:24,43 on [ D:\ ]
$ MOVE "D:\SOURCE\Heute Bin Ich Blond (2013)" D:\DESTINATION
1 dir(s) moved.
[ Orion@Oldskool-Desktop ] at 02-05-2016 2:55:24,43 on [ D:\ ]
$
above does work, but it's not the shortest, nicest, and lotsa tokens and switches to think of :
Code: Select all
@ECHO ON & CLS
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
FOR /D %%a IN (D:\SOURCE\*blond*) DO MOVE "%%a" D:\DESTINATION
[ Orion@Oldskool-Desktop ] at 02-05-2016 - 2:55:24,43 on [ D:\ ]
$ MOVE "D:\SOURCE\Heute Bin Ich Blond (2013)" D:\DESTINATION
1 dir(s) moved.
[ Orion@Oldskool-Desktop ] at 02-05-2016 2:55:24,43 on [ D:\ ]
$
-
- Newbie
- Posts: 2
- Joined: April 30th, 2016, 5:12 pm
Re: Help with creating a move script
Thanks Orion, for some reason the second one gave access denied error, but the first one worked.