Computer Hope

Microsoft => Microsoft DOS => Topic started by: CHF-Mark on November 09, 2022, 08:43:48 PM

Title: Move files to folders with similar names...
Post by: CHF-Mark on November 09, 2022, 08:43:48 PM
I am running Win 10 and would like to create a .bat file that accomplishes the following:

Checks each filename in a folder and then compares them to folder names in another folder.
If ANY part of the filenames match the folder name, move the file to that folder.

So files would be located in this folder:  d:\data\special\
And the folders to move these files to would be located here:  e:\

So here are some example files:
home garden.txt
Photos home.doc
Name home score.jpg

And here are some folder names to move the files into:
d:\garden
d:\presents
d:\chores
etc.

I'm sure a for loop would be needed to set this up but I don't have the skills
to write the code.

Any help would be appreciated!

I've searched online for this but nothing quite fits the bill.
Title: Re: Move files to folders with similar names...
Post by: CHF-Mark on November 10, 2022, 10:57:56 AM


So here are some example files:
home garden.txt
Photos home.doc
Name home score.jpg

And here are some folder names to move the files into:
d:\garden
d:\presents
d:\chores
etc.


I see I need to adjust my example folders a bit.  :)

And here are some folder names to move the files into:
d:\garden
d:\home
d:\presents
d:\chores
etc.

I hope it's clearer now.