2 points, one red, one green (see code)
(1) You need to set pos=0 for each file name. Your script sets it once and it just increases forever. No need to do set /a when creating a variable, only when you do arithmetic on it.
(2) To get a variable to work in a substring expression you need to use CALL SET (to make a child process expand the variable - and you need to double up the percent signs as shown)
@echo off
set cnt=0
setlocal enabledelayedexpansion
@for /f "delims=" %%a in ('Dir /b "%userprofile%\Desktop"') do (
REM (1)
set pos=0
set "filename=%%a"
Call:Stringloop "!filename!"
)
pause & exit
::**************************************************
:Stringloop <filename>
set "filename=%~1"
REM (2)
CALL Set "char=%%filename:~%pos%,1%%"
if "!char!"=="_" set /a cnt+=1
if "!char!"=="" echo !filename! : !cnt! & exit /b
set /a pos+=1
goto Stringloop
::*************************************************
Output...
HP : 0
iPlayer Recordings : 0
LockScreen Images by Winaero Tweaker : 0
Tor Browser : 0
Tor Browser2 : 0
Burn to the Brim.lnk : 0
Core Temp Gadget & Addons.url : 0
Core Temp.lnk : 0
desktop.ini : 0
Folder Size Explorer.lnk : 0
Folder Size.lnk : 0
FreeCommander XE.lnk : 0
Frhed.lnk : 0
Google Chrome Canary.lnk : 0
grub-choose-default.lnk : 0
HandBrake.lnk : 0
Intel© Power Gadget 3.0.lnk : 0
Internet Explorer.lnk : 0
MTPuTTY.lnk : 0
Namexif.lnk : 0
New_Text_Document_01.txt : 3
New_Text_Document_02.txt : 6
New_Text_Document_03.txt : 9
New_Text_Document_04.txt : 12
New_Text_Document_05.txt : 15
New_Text_Document_06.txt : 18
New_Text_Document_07.txt : 21
New_Text_Document_08.txt : 24
Nmap - Zenmap GUI.lnk : 24
NTLite.lnk : 24
Opera browser.lnk : 24
OSFMount.lnk : 24
ParNRar.lnk : 24
Perspective_Image_Correction.lnk : 26
Process Hacker 2.lnk : 26
QExplore 'My Computer'.lnk : 26
RapidBATCH 5.1 Personal Edition.lnk : 26
RMCDesigner.lnk : 26
RMPrepUSB.lnk : 26
SABnzbd.lnk : 26
Start Tor Browser.lnk : 26
Subtitle Edit.lnk : 26
Transmission Remote GUI.lnk : 26
VcXsrv.lnk : 26
Windows 10 Upgrade Assistant.lnk : 26
Windows 7 USB DVD Download Tool.lnk : 26
XLaunch.lnk : 26
Zipware.lnk : 26
Press any key to continue . . .