Reputation: 367
I have a folder with a bunch of subfolders. How would I wirte a bat file to append 8 random characters to the end of the folder names.
The first step I went through was placing files into the subfolders below, with this code:
for %%i in (PathToWorkingFolder\*) do mkdir "PathToWorkingFolder\%%~ni" & move "%%i" "PathToWorkingFolder\%%~ni"
The folder names are :
FD3_2012-10_Stmt
FD3_2012-10_Tax
FD3_2012-10_Warr
Upvotes: 1
Views: 466
Reputation: 67216
The two steps may be achieved in the same FOR:
@echo off
setlocal EnableDelayedExpansion
for %%i in (PathToWorkingFolder\*) do (
rem Get folder name with 8 random digits at end
digits=000000!random!!random!
set "folder=%%~Ni!digits:~-8!"
rem Create the subfolder and move the file
mkdir "PathToWorkingFolder\!folder!"
move "%%i" "PathToWorkingFolder\!folder!"
)
Upvotes: 1