Batch create folders from files with similar beginning but different ending -


i have lof of files similar beginning names, ending different. have create folder every "series" of files, means files names begin same 7 characers.

see image visualization: enter image description here

the code have right is
for /f "tokens=*" %%i in ('dir /b *.jpg') md "%%~ni"|copy "%%i" "%%~ni" creates folder every file , puts inside.

unfortunately don't have enough knowledge of language , googling made me learn how create substring set _result=%_test:~0,7% not how create folders that.

i'm sure it's short sequence, me that?

this may not efficient way of doing this, should you. below batch script takes input folder , output folder inputs user. iterates through files in input folder , copies them output folder under sub-folder first 7 characters of filename.

@echo off setlocal enabledelayedexpansion rem input directory user set /p input_dir=please enter full path directory files: rem ouput directory user set /p output_dir=please enter full path output directory: rem iterate through files , create necessary folders/copy files /f %%f in ('dir /b %input_dir%') (     set fullname=%%f     set trimmedname=!fullname:~0,7!     set fullpath=%output_dir%\!trimmedname!     if not exist !fullpath! md !fullpath!     copy %input_dir%\%%f !fullpath! ) 

here's sample output shows processing done script:

ouptut


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -