0

Please check this...

It create a folder for x number of file recursively, but the MOVE command check also on subufolder of destination_folder=Destination Folder and create a wrong number of empty folder. How to exclude destination_folder from the For...Do? Thanks

2
  • for /r is always recursively. Commented Apr 8, 2013 at 11:25
  • I know /R is always recursively, but the problem it is recursively also in new created subdir, so also to "C:\My Folder\Destination Folder" and i what to avoid/exclude that from loop or alternative solution Commented Apr 8, 2013 at 11:43

1 Answer 1

1

Just add a check to see whether %destination_folder% exists within %%~pF.

FOR /R "%folder%" %%F IN (*.*) DO (

    rem --- add this ---
    set "loopfolder=%%~pF"
    if "%%~pF"=="!loopfolder:%destination_folder%=!" (
    rem ----------------

        if !n!==1 (
        etc.

... which basically means, after stripping the value of %destination_folder% from the value of the path of %%F, if nothing changed, then the path doesn't include the destination folder. Proceed.

Sign up to request clarification or add additional context in comments.

3 Comments

Please can you can be more specific? If i found %destination_folder% what i can do? I need to exclude that, not include. Thanks
I'm not sure what you're asking. If your loop value %%F contains "Destination Folder", you want to continue to the next iteration without any action, right? That's what this does. If the loop value %%F does not contain the text "Destination Folder", then whatever is within the if statement should execute.
If have test it, not work as expected. It create the correct number of folder ( example 40 files = 4 folder ) but it put all the file in the last folder, not 10 number of file in each folder. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.