# batch script to seperate file name into 4 different parts

December 26, 2011 at 22:49:54
Specs: Windows XP
 Hi guys, I just started using batch script for my work and I am required to seperate multiple file names into 4 different parts. eg zxcf1g2h3. I am suppose to seperate it into zxc f1 g2 h3. I need to do this for multiple files with zxc as the only constant in the file name. Thanks for the help and happy new year! Wei

See More: batch script to seperate file name into 4 different parts

#1
December 27, 2011 at 14:00:44

Report •

#2
December 27, 2011 at 18:48:13
 eg. zxcs1g2h3 zxcs2g3h4 zxcn1g3h3i need to seperate them into this format: zxc s1 g2 h3 and do the same for the rest of the files, which is a lot. The output needs to be horizontal, not like eg zxc s1 g2 h3ThanksWei

Report •

#3
December 27, 2011 at 23:03:09
 Please test this script.@echo off cls setlocal enabledelayedexpansion pushd path\to\files\||echo Pushd failed - job terminated.&&exit /b for /f "tokens=*" %%1 in ('dir /a-d /b zxc*') do ( set filein=%%1 set fileout=!filein:~0,3! !filein:~3,2! !filein:~5,2! !filein:~-2! echo !fileout!>>outputfile.txt ) Please come back & tell us if your problem is resolved.

Report •

Related Solutions

#4
December 27, 2011 at 23:27:27
 Hi Wahine,Thanks for your reply but i do not understand what your program does, can you explain what it does at "pushd" and onwards? it does not seems to work though, and I need to output the result into a text file.ThanksWei

Report •

#5
December 28, 2011 at 00:06:31
 In the Pushd command line you must supply the path to the files to be processed. Enter pushd /? at the command prompt to display instructions and explanation.The rest is a standard For loop, enter For /? at the command prompt to display instructions and explanation.Enter other commands following by /? at the command prompt to display instructions and explanations.I have modified the script to output the results to a text file, you did not ask for this in your original post.Please come back & tell us if your problem is resolved.

Report •

#6
December 28, 2011 at 00:44:29
 Hi Wahine,Thanks for your help! The program is working fine. My bad on not posting all the information in one go. Have a good day.ThanksWei

Report •