Thanks for the response.
trrying to answer your question:
I am not concatenating the all the file contents into one file but will write to different file by appending file name folder name and line no.
Let say I have parent folder (A1). Under the parent folder A1 it has different subfolder A12,A13, A14 and A15. I want to read this folder name and file name and content of each filename under each folders. Could be some folders do not contain any file then I should not process that folders.
It is in continuation of the requirement.
I am using this code and listing the folders and files inside the folders by a looping the folders but encountering few issues while reading files and printing few name.
Sample input file is provide below.
Also i need to print the line numbers along with the rows.
Code: Select all
@echo off
setlocal enabledelayedexpansion
set WORKING_DIRECTORY=%cd%
pushD %WORKING_DIRECTORY%
for /f "usebackq tokens=*" %%a in (`dir /b/s/a:d MigrationPoc`) do (
echo:%%~nxa
set "vfolder=%%~nxa"
echo folder name %vfolder% ;
for /f "usebackq tokens=*" %%a in (`dir /a-d /b %%a` ) do (
echo:%%~na
set vfilename=%%~na
set /p "header="<"%vfilename%"
set "header=%header:|=,%"
FOR /F "skip=1 usebackq delims=" %%G IN ("%vfilename%") DO (
set "line=%%~G"
set line="!line:|=","!"
REM# also i need to print the line number starting from 2
echo %header%##!line!##%vfolder%.%vfilename%
)
)
)
pause
popD
output:
Code: Select all
F1----->Folder name appearing properly
folder name ; ----> Folder name is not appearing
u1 ----> File name
The system cannot find the path specified. --->Output is not coming but the file is present in the path
sample output:
COMPID,COMPNAME,ADDRESS,YEAROFESTABLISTMENT##"100","XYC","AWER RD","12072018"##F1.u1##<line no> 2
COMPID,COMPNAME,ADDRESS,YEAROFESTABLISTMENT##"120","BNM","PQTY RD","12082018"##F1.u1##<line no> 3
The system cannot find the file .
b1
The system cannot find the path specified.
The system cannot find the file .
c1
The system cannot find the path specified.
The system cannot find the file .
d1
The system cannot find the path specified.
The system cannot find the file .
Sch_B
folder name ;
File Not Found ---->If there is not file inside a folder then file not found should not be print.It should be skipped.
Sch_C
folder name ;
File Not Found
Sch_D
folder name ;
a1
The system cannot find the path specified.
The system cannot find the file .
b1
The system cannot find the path specified.
The system cannot find the file .
c1
The system cannot find the path specified.
The system cannot find the file .
d1
The system cannot find the path specified.
The system cannot find the file .
Sample input file u1:
Code: Select all
COMPID|COMPNAME|ADDRESS|YEAROFESTABLISTMENT
100|XYC|AWER RD|12072018
120|BNM|PQTY RD|12082018