How to add containing folders to collection of files

Page 1 of 4 123 ... LastLast

  1. Posts : 1
    Windows 10
       #1

    How to add containing folders to collection of files


    I have several thousand files that I want put into individual folders of the same name. Does anyone know of a batch method for this?
      My Computer


  2. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #2

    Hello @Fundeby,

    Welcome to TenForums!

    Fundeby said:
    I have several thousand files that I want put into individual folders of the same name. Does anyone know of a batch method for this?
    [1] Are ALL the files currently in the same directory?
    [2] Do you want ALL the created folders put into that same directory?
      My Computer


  3. Posts : 869
    Windows 10 Professional x64 21H2
       #3

    Paul Black said:
    Hello @Fundeby,

    Welcome to TenForums!


    [1] Are ALL the files currently in the same directory?
    [2] Do you want ALL the created folders put into that same directory?
    I can't wait to see what you come up with Paul. Because I was thinking something similar for myself as I have 10's of thousands of files on 5 or 7 drives. Waiting in anticipation.
      My Computers


  4. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #4

    Hello @Fundeby,

    Create a Files_To_Folders.bat file with the code below in the directory that the files are in.

    This batch script creates a folder for each filename in the directory that the batch script resides in and then populates [ moves ] them with the files accordingly. The folders names will be a mirror image of the filenames themselves, excluding the suffix.

    WARNING: Setup a test directory directory that includes a selection of filenames FIRST and then run the batch script to ensure that the results are correct and as expected.

    Code:
    @echo off
    title Files To Folders - Written by Paul Black.
    echo. & echo  Processing . . . & echo.
    for %%i in (*) do (
      if not "%%~ni" == "Files_To_Folders" (
        md "%%~ni" && move "%%~i" "%%~ni"
      )
    )
    echo. & echo ^>Press ANY key to EXIT . . . & pause >nul
    I hope this helps!
    Last edited by Paul Black; 03 Jul 2020 at 12:10.
      My Computer


  5. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #5

    Hello @Lance1,

    Lance1 said:
    I can't wait to see what you come up with Paul. Because I was thinking something similar for myself as I have 10's of thousands of files on 5 or 7 drives. Waiting in anticipation.
    Give the code above a try. I setup a folder and copied some files into it [ .txt, .png, .jpg, .odt etc ] and then ran my code and it worked OK!

    I hope this helps!
    Last edited by Paul Black; 01 Jul 2020 at 16:43.
      My Computer


  6. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #6

    Hello @Lance1,

    If you think it will also be useful to have the total number of folders created and the files moved let me know and I will adapt the code accordingly. I can also adapt the code so it doesn't show the long list of 1 file(s) moved..
    Last edited by Paul Black; 01 Jul 2020 at 17:20.
      My Computer


  7. Posts : 869
    Windows 10 Professional x64 21H2
       #7

    Paul Black said:
    Hello @Lance1,

    If you think it will also be useful to have the total number of folders created and the files moved let me know and I will adapt the code accordingly. I can also adapt the code so it doesn't show the long list of 1 file(s) moved..
    Yes I think that would be useful Paul thank you.
      My Computers


  8. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #8

    Here you go @Lance1,
    Code:
    @echo off
    title Files To Folders - Written by Paul Black.
    set count=-1
    echo. & echo  Processing . . .
    for %%j in (*) do set /A Count +=1
    for %%i in (*) do (
      if not "%%~ni" == "Files_To_Folders" (
        md "%%~ni" && move "%%~i" "%%~ni" >nul
      )
    )
    echo. & echo  Created %Count% folders and moved the files successfully!
    echo. & echo ^>Press ANY key to EXIT . . . & pause >nul
    Please let me know how it works for you [ see Post #4 for warnings and advice ]!

    I hope this helps!
      My Computer


  9. Posts : 869
    Windows 10 Professional x64 21H2
       #9

    Paul Black said:
    Here you go @Lance1,
    Code:
    @echo off
    title Files To Folders - Written by Paul Black.
    set count=-1
    echo. & echo  Processing . . .
    for %%j in (*) do set /A Count +=1
    for %%i in (*) do (
      if not "%%~ni" == "Files_To_Folders" (
        md "%%~ni" && move "%%~i" "%%~ni" >nul
      )
    )
    echo. & echo  Created %Count% folders and moved the files successfully!
    echo. & echo ^>Press ANY key to EXIT . . . & pause >nul
    Please let me know how it works for you [ see Post #4 for warnings and advice ]!

    I hope this helps!
    Thanks Paul. I just got home, I got a few things to put away. I'm going to format one of my flash drives and take this .BAT for a test drive.
      My Computers


  10. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #10

    Lance1 said:
    Thanks Paul. I just got home, I got a few things to put away. I'm going to format one of my flash drives and take this .BAT for a test drive.

    It's nearly midnight here so I will be off to bed shortly!
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 12:06.
Find Us




Windows 10 Forums