I have files in the following format 123~12345.aaa - I need to extract files from their C:\ location into a corresponding folder based on filename ie copy C:\123~*.aaa to C:\123\123~*.aaa
THIS IS UNTESTED. I set this up to create a folder called "testfolder", and also to copy and not move in case something is wrong with it. @echo off
REM outputting list of files to temp file
dir /b c:\*.aaa > filelist.tmp
REM looping through list to cut the filenames down to their first three digits
for /F "tokens=*" %%A in (filelist.tmp) do (
set dir=%A:~0,3%
REM creating a list of future directory names
echo %dir% >> dirlist.tmp
)
REM looping through dirlist.tmp to make directories
for /F "tokens=*" %%A in (dirlist.tmp) do (
if not exist c:\testfolder\%%A md c:\testfolder\%%AREM looping through dirlist.tmp to move files into new directories
for /F "tokens=*" %%A in (dirlist.tmp) do (
copy c:\%%A*.* c:\%%A\REM deleting temp files
del /q filelist.tmp
del /q dirlist.tmp
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |