Solved batch to add filename in the first column wo fileextens

August 23, 2012 at 06:07:48
Specs: Windows 7, i7/32GB RAM
Hi

I found this code here, but I have a problem because it adds the fileextension too. I would like to only add the filename, which has different length, sometimes 3 letters, other times it might be 6 letters. Here is my code so far:

@echo off & setLocal EnableDELAYedeXpansion
for /f "tokens=* delims= " %%a in ('dir/b/a-d *.csv') do (
@echo off > #
for /f "tokens=* delims= " %%i in (%%a) do (
>> # echo.%%a, %%i
)
move /y # %%a
)

Kind regards
Espen


See More: batch to add filename in the first column wo fileextens

Report •


#1
August 23, 2012 at 10:04:11
can you use %%~na

:: mike


Report •

#2
August 23, 2012 at 10:11:46
I'm not sure how anything of these codes work. I have only been working in VBA, but then I realized that I had to do some changes because VBA is so slow.

I'm afraid I have to ask where I should put the %%~na

Kind regards
Espen


Report •

#3
August 23, 2012 at 11:36:37
✔ Best Answer
I believe you can replace this
>> # echo.%%a, %%i
with
>> # echo.%%~na, %%i

I think this will work, I guess I would always recommend testing it.

:: mike


Report •

Related Solutions

#4
August 23, 2012 at 13:11:38
Thanks Mike!! That worked perfect!

May I ask if it is possible to involve the merge-process in this code too? Or is it best to make that as an operation number two from the dos-command copy *.csv merged.csv?

Kind regards
Espen


Report •

#5
August 23, 2012 at 14:20:52
I regret to say that I am no expert when it comes to .csv files, Unfortunatly it might be best for someone more in the know so it might be best to ask a new question/

:: mike


Report •

#6
August 23, 2012 at 14:35:46
Ok, it's no big deal, because I will do this operation very rare, so I can do it in two sequences.

Thank you anyway, you've been very helpful.

Kind regards
Espen


Report •

#7
August 23, 2012 at 16:28:03
Thank you for the feedback, sorry it was only a partial answer

:: mike


Report •


Ask Question