Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
drgt
- Posts: 160
- Joined: 21 Sep 2010 02:22
- Location: Greece
#1
Post
by drgt » 07 Mar 2017 02:25
In the following batch
Code: Select all
for /f "delims=" %%a in ('dir D:\Data\Test /a-d /on /b') do (
copy "D:\Data\Test\%%a" "C:\Test"
I would like to set the source and target in the beginning of the file.
e.g
source=D:\Data\Test
target=C:\Test
and then modify the code accordingly.
Could you please show me?
-----------------------------------
For example, this does NOT work:
Code: Select all
set source=D:\Data\Test
set target=C:\Test
for /f "delims=" %%a in ('dir %source% /a-d /on /b') do (
copy "%source%\%%a" "%target%"
set source=
set target=
-
drgt
- Posts: 160
- Joined: 21 Sep 2010 02:22
- Location: Greece
#3
Post
by drgt » 07 Mar 2017 03:21
THANK YOU !!!
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#4
Post
by Squashman » 07 Mar 2017 08:48
This isn't a problem with setting variables. You are basically not using parentheses correctly. Looking back at the code you were given in previous questions you were shown how to use parentheses correctly with the FOR command.
Regardless of that you could just put this all on one line and not bother with the parentheses.
Code: Select all
for /f "delims=" %%a in ('dir %source% /a-d /on /b') do copy "%source%\%%a" "%target%"
-
drgt
- Posts: 160
- Joined: 21 Sep 2010 02:22
- Location: Greece
#5
Post
by drgt » 09 Mar 2017 01:19
Thank you for pointing that out!