4

I am using this in my program

for %%I in (*.txt) do (

The filename is in %%I.

Now i want to separate the first 2 chracters, next 3 characters, separately.

Is this possible in DOS or Cmd.exe?

Daniel F
  • 1,013
Mirage
  • 3,183

3 Answers3

7

http://www.dostips.com/DtTipsStringManipulation.php

set first2=%%I:~0,2% && set next3=%%I:~3,3%

I think.. geez, its been a while!

Grizly
  • 869
1
@echo off 
setlocal enabledelayedexpansion
for %%a in (*.mp3) do ( 
  set oldName=%%a 
  Set newName=!oldName:~3! 
  Ren "!oldName!" "!newName!" ) 
exit

_Strip 3.cmd is a good name to save this to. Works for me. I have it (.mp3) to only work with mp3 files ... you can change it to (.*)

Change the ~3! to another number if you want to...... ~4! will truncate the first 4 characters of the file name.

Daniel F
  • 1,013
0

In Powershell:

$first2=$string.substring(0,2)
$next3=$string.substring(2,3)
Wasif
  • 8,474