I’m trying to create an automation in a batchfile to create folders from filenames and move the files with a different filename to this new created folders.
I’ve got a bunch of Excel files and the first few tokens are the same in these files.
So for the created folders i need to remove the first 12 tokens and the extensions.
Only managed to adjust the filenames, but the folders need the same name without the extensions .xlsx.
I saw this code and tried to adjust it.
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "SourceDir=C:Bureaublad1"
set "DestDir=C:Bureaublad1"
for /F "eol=| delims=" %%A in ('dir /B /A-D-H "%SourceDir%Kamekllofis*.*" 2^>nul') do (
for /F "eol= tokens=1 delims=." %%B in ("%%~nA") do (
md "%DestDir%%%B" 2>nul
set "FileName=%%A"
call move /Y "%SourceDir%%%A" "%DestDir%%%B%%FileName:~12%%"
)
)
Tried this
md "%DestDir%%%B:~12%%" 2>nul
I just need the first characters from the filename removed and the extension .xlsx