Page 1 of 1

move files according to folder

Posted: 05 Nov 2011 19:08
by leescott
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

Re: move files according to folder

Posted: 06 Nov 2011 04:50
by Ed Dyreen
'
That code could never work, where is your do clausule ?:

Code: Select all

for /f "delims=  tokens=1" %%i in (b2.txt) 
do ??

Re: move files according to folder

Posted: 06 Nov 2011 06:14
by leescott
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

Re: move files according to folder

Posted: 10 Nov 2011 19:42
by leescott
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

Re: move files according to folder

Posted: 11 Nov 2011 01:01
by leescott
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

Re: move files according to folder

Posted: 11 Nov 2011 07:56
by Ed Dyreen
'
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


Re: move files according to folder

Posted: 11 Nov 2011 23:33
by leescott
Thanks!
Maybe I'm too eagerly to get correct answer,I'm sorry for my actions.
In the bat ,no "move",no work.

Re: move files according to folder

Posted: 14 Nov 2011 18:50
by leescott
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.