Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
leescott
- Posts: 7
- Joined: 05 Nov 2011 18:58
#1
Post
by leescott » 05 Nov 2011 19:08
I want to move files according to folder names.Some folder names have been writen in b2.txt.
I'm foreign to DOS.And I learn a little,edit a bat like follow.Please give me some modification.Thanks!!
Code: Select all
@echo off
for /f "delims= tokens=1" %%i in (b2.txt)
for /f "delims= tokens=2" %%j in (b2.txt)
for /f "delims=*" %%k in ('dir /s/b/a-d E:\JP-WKA\*.pdf E:\JP-WKA\*.txt ^| findstr /i "%%i"^|findstr /i "%%j"')
for /f "delims=" %%l in ('dir /s/b/a:d-h E:\ ^|findstr /i "%%i"^|findstr /i "%%j"'>nul') do (
if not "%%l"=="" move "%%k" "%%~dpl" >nul 2>nul
)
pause
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#2
Post
by Ed Dyreen » 06 Nov 2011 04:50
'
That code could never work, where is your do clausule ?:
Code: Select all
for /f "delims= tokens=1" %%i in (b2.txt)
do ??
-
leescott
- Posts: 7
- Joined: 05 Nov 2011 18:58
#3
Post
by leescott » 06 Nov 2011 06:14
Ed Dyreen wrote:'
That code could never work, where is your do clausule ?:
do ??
Thanks!
My b2.txt like this:
conformal coating
memory device
Code: Select all
@echo off
for /f "delims=* tokens=1-2" %%i in (b2.txt)
for /f "delims=*" %%k in ('dir /s/b/a-d E:\JP-WKA\*.pdf E:\JP-WKA\*.txt ^| findstr /i "%%i %%j"') do (
for /f "delims=" %%l in ('dir /s/b/a:d-h E:\ ^|findstr /i "%%i %%j"'>nul') do (
if not "%%l"=="" move "%%k" "%%~dpl" >nul 2>nul
))
pause
-
leescott
- Posts: 7
- Joined: 05 Nov 2011 18:58
#4
Post
by leescott » 10 Nov 2011 19:42
please help me!
I edit it as next,but it don't work.What's wrong?
I guess wrong may be in "for /f "delims= tokens=1,2" %%i in (b2.txt) do (
'echo "%%i" "%%j"'|".
But I can't find key to answer.
Code: Select all
@echo off
for /f "delims= tokens=1,2" %%i in (b2.txt) do (
'echo "%%i" "%%j"'|for /f "delims=*" %%k in ('dir /s/b/a-d E:\JP-WKA\*.pdf E:\JP-WKA\*.txt ^| findstr /ig:"%%i"^|findstr /ig:"%%j"') do (
for /f "delims=*" %%l in ('dir /s/b/a:d-h E:\ ^| findstr /i "%%i"^|findstr /i "%%j" 2^>nul') do (
if not "%%l"=="" move "%%k" "%%~dpl" >nul 2>nul
)))
pause
-
leescott
- Posts: 7
- Joined: 05 Nov 2011 18:58
#5
Post
by leescott » 11 Nov 2011 01:01
How to combine two codes together?
How to make last code use "%%i""%%j" gotten from first code?
Thanks for your help!
Code: Select all
@echo off
for /f "usebackq tokens=1,2 delims= " %%i in (b2.txt)
do(echo %%i %%j)
Code: Select all
for /f "delims=" %%k in ('dir /s/b/a-d E:\JP-WKA\*.pdf E:\JP-WKA\*.txt ^| findstr /i "%%i"^|findstr /i "%%j"') do (
for /f "delims=" %%l in ('dir /s/b/a:d-h E:\ ^| findstr /i "%%i"^|findstr /i "%%j" 2^>nul') do (
if not "%%l"=="" move "%%k" "%%~dpl" >nul 2>nul
))
pause
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#6
Post
by Ed Dyreen » 11 Nov 2011 07:56
'
try this, I didn't test it because I have work to do sorry things are vague, I can't see why it wouldn't work, (pm) if you want to draw attention just bump your post, but not too often and only after a few days, otherwise you'll just upset the community.
Code: Select all
@echo off &SetLocal EnableExtensions EnableDelayedExpansion
for /f "usebackq tokens=1,2 delims= " %%a in (
"b2.txt"
) do(
echo.a=%%~a_, b=%%~b_
set /a $error = 0
::
for /f "delims=" %%? in (
'2^>nul dir /b /a:-D /s "E:\JP-WKA\*.pdf" "E:\JP-WKA\*.txt"
) do (
if /i ["%%~a"] == ["%%~?"] (
set /a $error += 1
)
if /i ["%%~b"] == ["%%~?"] (
set /a $error += 1
)
)
if !$error! equ 2 (
::
set /a $error = 0
::
for /f "delims=" %%? in (
'2^>nul dir /b /a:D-H /s "E:\"'
) do (
if /i ["%%~a"] == ["%%~?"] (
set /a $error += 1
)
if /i ["%%~b"] == ["%%~?"] (
set /a $error += 1
)
)
if !$error! equ 2 (
::
echo.I'm unsure what you plan to do here, sorry.
)
)
)
pause
-
leescott
- Posts: 7
- Joined: 05 Nov 2011 18:58
#7
Post
by leescott » 11 Nov 2011 23:33
Thanks!
Maybe I'm too eagerly to get correct answer,I'm sorry for my actions.
In the bat ,no "move",no work.
-
leescott
- Posts: 7
- Joined: 05 Nov 2011 18:58
#8
Post
by leescott » 14 Nov 2011 18:50
Ed Dyreen wrote:'
try this, I didn't test it because I have work to do sorry things are vague, I can't see why it wouldn't work, (pm) if you want to draw attention just bump your post, but not too often and only after a few days, otherwise you'll just upset the community.
Code: Select all
@echo off &SetLocal EnableExtensions EnableDelayedExpansion
for /f "usebackq tokens=1,2 delims= " %%a in (
"b2.txt"
) do(
echo.a=%%~a_, b=%%~b_
set /a $error = 0
::
for /f "delims=" %%? in (
'2^>nul dir /b /a:-D /s "E:\JP-WKA\*.pdf" "E:\JP-WKA\*.txt"
) do (
if /i ["%%~a"] == ["%%~?"] (
set /a $error += 1
)
if /i ["%%~b"] == ["%%~?"] (
set /a $error += 1
)
)
if !$error! equ 2 (
::
set /a $error = 0
::
for /f "delims=" %%? in (
'2^>nul dir /b /a:D-H /s "E:\"'
) do (
if /i ["%%~a"] == ["%%~?"] (
set /a $error += 1
)
if /i ["%%~b"] == ["%%~?"] (
set /a $error += 1
)
)
if !$error! equ 2 (
::
echo.I'm unsure what you plan to do here, sorry.
)
)
)
pause
I have done it by myself.
I'm not expert.I request man to help me editing batchfile.Some will be kindness,some will be gone with unconcern,even be unkindness.
I think ,Good will Be rewarded with good, and evil with evil.