How To Concatenate a String/Character

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
warrentolentino
Posts: 9
Joined: 02 Oct 2014 11:54

How To Concatenate a String/Character

#1 Post by warrentolentino » 20 Nov 2018 08:19

we have a multiple scripts (*.sql) that is spread out of multiple subfolders. i need to get all of those scripts in one script including the subfolder paths. i use this command:

Code: Select all

dir *.* /s /b /a-d > warren.sql
this works fine it will list all the files including the subfolder path and puts it in one file warren.sql.

for example:

Code: Select all

z:\warren>
11/19/2018  03:38 PM    <DIR>          .
11/19/2018  03:38 PM    <DIR>          ..
11/19/2018  11:25 AM    <DIR>          APPS

z:\warren\APPS>
z:\warren\APPS>dir
 Volume in drive z is HOME
 Volume Serial Number is 2736-G3SD

 Directory of O:\warren\APPS

11/19/2018  11:25 AM    <DIR>          .
11/20/2018  08:45 AM    <DIR>          ..
11/19/2018  11:25 AM    <DIR>          001TABLES
11/19/2018  11:25 AM    <DIR>          002VIEWS
11/19/2018  11:25 AM    <DIR>          003TRIGGERS
11/19/2018  11:25 AM    <DIR>          004PROCEDURES
               0 File(s)              0 bytes
               3 Dir(s)  5,346,648,166,400 bytes free

z:\warren\APPS>cd 001TABLE
z:\warren\APPS\001TABLE> dir/od
 Volume in drive z is HOME
 Volume Serial Number is 2736-G3SD


 Directory of z:\warren\APPS\001TABLES>

11/14/2018  02:39 PM             2,650 TAB001.sql
11/14/2018  02:39 PM               771 TAB002.sql
11/14/2018  02:39 PM               566 TAB003.sql
               9 File(s)          3,987 bytes
               2 Dir(s)  5,346,616,463,360 bytes free           

z:\warren\APPS\001TABLE>cd \warren
z:\warren>dir *.* /s /b /a-d > warren.sql
z:\warren>type warren.txt
z:\warren\APPS\001TABLES\TAB001.sql
z:\warren\APPS\001TABLES\TAB002.sql
z:\warren\APPS\001TABLES\TAB003.sql
but i need to add a semicolon ";" character at the end of the file name
for example

Code: Select all

 z:\warren\APPS\001TABLES\TAB001.sql;
 z:\warren\APPS\001TABLES\TAB002.sql;
 z:\warren\APPS\001TABLES\TAB003.sql;
how do i concatenate a string/character using a dir command? thank you

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How To Concatenate a String/Character

#2 Post by aGerman » 20 Nov 2018 11:02

Code: Select all

(for /f "delims=" %i in ('dir *.* /s /b /a-d') do @echo %i)>"warren.sql"
Double the percent signs (%i to %%i) if you want to use it in a Batch script.

Steffen

warrentolentino
Posts: 9
Joined: 02 Oct 2014 11:54

Re: How To Concatenate a String/Character

#3 Post by warrentolentino » 20 Nov 2018 11:22

thank you.

i only added the semicolon to your code and it works

Code: Select all

(for /f "delims=" %i in ('dir *.* /s /b /a-d') do @echo %I;) > "warren.sql"

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How To Concatenate a String/Character

#4 Post by aGerman » 20 Nov 2018 11:27

Oh I forgot. But note that FOR variables are case sensitive. %i ist not the same as %I.

Steffen

Post Reply