Search code examples
batch-filedos

DOS batch process to move files to relevant folders


I want to write a DOS batch process which will go through my Directory and move all *.txt files to a dest folder to starting with the first character of the txt files

Ex.
abc.txt will move to folder "a"
def.txt will move to folder "d"
and so on...


Solution

  • From the command line:

    for %i in (*.txt) do (set FOLDER=%i & move %i %FOLDER:~0,1%)
    

    In a batch file, you would have to double the %'s, like this:

    for %%i in (*.txt) do (set FOLDER=%%i & move %%i %FOLDER:~0,1%)