how to write content separated by comma in a text file
Moderator: DosItHelp
how to write content separated by comma in a text file
Hi all,
I executed the command
DIR *.csv \b > sample.txt
The output is
file1.csv
file2.csv
file3.csv
But i need output like
file1.csv,file2.csv,file3.csv
Note : After file3.csv, comma should not be there. Please throw some light on this. Thank you..
Regards,
babhuko
I executed the command
DIR *.csv \b > sample.txt
The output is
file1.csv
file2.csv
file3.csv
But i need output like
file1.csv,file2.csv,file3.csv
Note : After file3.csv, comma should not be there. Please throw some light on this. Thank you..
Regards,
babhuko
Re: how to write content separated by comma in a text file
% and ^ and comma characters in the filenames will cause a problem.
Code: Select all
@echo off
for /f "delims=" %%a in ('DIR *.csv /b 2^>nul') do (
set /p ="%%a," <nul >>"sample.txt"
)
set /p "var=" <"sample.txt" >nul
set "var=%var:~0,-1%"
echo(%var%>sample.csv
del "sample.txt"
Re: how to write content separated by comma in a text file
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set line=
for %%a in (*.csv) do set "line=!line!,%%a"
echo !line:~1!> sample.txt
Re: how to write content separated by comma in a text file
Thanks for the reply. Its working.
I have another issue.
In this error is in the rename command.
I dont know what it is. %3 is the filename am passing as a parameter from ETL tool. Before rename it works. but only rename throws some error. Please advice.
Thanks,
Dosuser
I have another issue.
Code: Select all
@echo off
SET DATE_DIS=none
set DATE_DIS=%date%%time%
move %1%3 %2
cd %2
rename %3 %3_%DATE_DIS%
pause
In this error is in the rename command.
I dont know what it is. %3 is the filename am passing as a parameter from ETL tool. Before rename it works. but only rename throws some error. Please advice.
Thanks,
Dosuser
Re: how to write content separated by comma in a text file
add echo before the rename
ECHO rename %3 %3_%DATE_DIS%
And see what is on the screen when the pause prompt appears.
ECHO rename %3 %3_%DATE_DIS%
And see what is on the screen when the pause prompt appears.
Re: how to write content separated by comma in a text file
The date might contain / and the time might contain : which are both illegal filename characters.
Re: how to write content separated by comma in a text file
@foxidrive,
Thanks for your info. Could you please let me know how to avoid that error.
I mean l have given DATE_DIS = %date%%time%. Any other format there like only with numerals to avoid this issue.
For eg
yyyymmddhhmiss
Please advise.
Thanks
Thanks for your info. Could you please let me know how to avoid that error.
I mean l have given DATE_DIS = %date%%time%. Any other format there like only with numerals to avoid this issue.
For eg
yyyymmddhhmiss
Please advise.
Thanks
Re: how to write content separated by comma in a text file
Code: Select all
set DATE_DIS=%date:/=%%time::=%
Re: how to write content separated by comma in a text file
Code: Select all
:: timestamp YYYYMMDD_HHMMSS
@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set datetime=%dt:~0,8%_%dt:~8,6%
This is a good method and works in any region.
Re: how to write content separated by comma in a text file
@foxidrive
I have used your datetime code. but still the same issue. Please advise
I have used your datetime code. but still the same issue. Please advise
Code: Select all
@echo off
SET DATE_DIS=none
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set DATE_DIS=%dt:~0,8%_%dt:~8,6%
move %1%3 %2
cd %2
rename %3 %3_%DATE_DIS%
pause
Re: how to write content separated by comma in a text file
This will echo the rename command - see what it shows.
Code: Select all
@echo off
SET DATE_DIS=none
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set DATE_DIS=%dt:~0,8%_%dt:~8,6%
move %1%3 %2
cd %2
echo rename %3 %3_%DATE_DIS%
pause