1.

Solve : Move a file that begins with A or a, to a subfolder?

Answer»

I would like to know how to Move all folders in a subfolder that start with an "A or a" to ANOTHER folder found in a subfolder called A.
I would like to do the whole alphabet if possible.

Any assistance would be greatly appreciated.

Thank you
EDIT: The subject says files but your description says folders. Make up your mind.

Try this on some sample folders.

Code: [Select]@echo off
for %%z in (a b c d e f g h i j K l m n o p q r s t u V w x y z) do (
for /f "delims=" %%a in ('dir "%%z*" /b /ad 2^>NUL') do (
md "!Folder %%z" 2>nul
move "%%a" "!Folder %%z" >nul
)
)
pause
This works for files - but don't put the batch file in the same folder, set the folder path in the second line.

There could be issues because the DIR command searches both the short and long filename so you can get false matches. I can't think of any way around that, matching on only one character.

Code: [Select]@echo off
pushd "c:\folder\to check"
for %%z in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
for /f "delims=" %%a in ('dir "%%z*" /b /a-d 2^>nul') do (
md "%%z" 2>nul
move "%%a" "%%z" >nul
)
)
popd
pause
Quote from: foxidrive on October 21, 2012, 10:14:44 PM

EDIT: The subject says files but your description says folders. Make up your mind.

Try this on some sample folders.

Code: [Select]@echo off
for %%z in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
for /f "delims=" %%a in ('dir "%%z*" /b /ad 2^>nul') do (
md "!Folder %%z" 2>nul
move "%%a" "!Folder %%z" >nul
)
)
pause

Sorry for the confusion.
Should have been folders Not Files...
Mind moving a mile a minute...
Thank you for the response!
Quote from: foxidrive on October 21, 2012, 10:14:44 PM
EDIT: The subject says files but your description says folders. Make up your mind.

Try this on some sample folders.

Code: [Select]@echo off
for %%z in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
for /f "delims=" %%a in ('dir "%%z*" /b /ad 2^>nul') do (
md "!Folder %%z" 2>nul
move "%%a" "!Folder %%z" >nul
)
)
pause

Parent Directory folder containing subfolders folders that begin with letters. Move the sub folders to matching first letter folders located in a sub folder on the hard drive.
Again sorry for the confusion. I will be well thought out before I post again.Try that batch file in your reply then.

It will move all the folders into one set of folders in the same directory. They will be called
"!folder a"
"!folder b"
"!folder c"
"!folder d"
etc.I already have existing folders lettered from a-z.
I just am trying to copy folders to those in a different location that already exist.
Code: [Select]@echo off
for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do move "%%a" "d:\backup\folder\"


Discussion

No Comment Found