Batch file to write filenames from a directory into a text file with specific format

Try_Learning

Wanted to write a batch file that reads file names from a directory and puts them into a text file in the same directory. Twist is that the filenames should have specific format explained below: Original file names are: ThisThat.shp, HellNono.shp, LifeGood.shp.... and so on. So the batch file should grab ThisThat, HellNono, LifeGood and put it into a text file like this:

ThisThat|ThisThat
HellNono|HellNono
LifeGood|LifeGood

filenames should be separated with a separator and each filename in a different line.

This is what I have come up with.

cd %1
if exist 8characters.txt del 8characters.txt
for /F "delims=" %%j in ('dir /A-D /B /O') do echo %%~nj >> 8characters.txt

This script just grabs filenames and I don't know how to store it in the format explained above.Any help will be greatly appreciated. Thanks

a_horse_with_no_name

You are nearly there as %%~nj will output the filename as you want it. You just need to output it twice to get the format you want:

for /F "delims=" %%j in ('dir /A-D /B /O') do echo %%~nj^|%%~nj>> 8characters.txt

Note the ^ character in front of the |. The | is used to pipe the output to another command so it needs to be escaped and that is done using ^|

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Batch file with spaces in variables/filenames in text file

From Java

Batch File; List files in directory, only filenames?

From Dev

Batch file to process filenames ending in specific characters

From Dev

Create txt file from batch file with specific date format in it

From Dev

Batch file to delete specific text file from multiple locations

From Dev

Grab the filenames of the file from the directory and change as per string manipulation like String Concatination in BATCH script

From Dev

Filenames with . in batch file

From Dev

Read text file and write file from specific contents

From Dev

Batch file to not write variables in a text file

From Dev

Batch - Copy specific text from one file to another

From Dev

Copying a specific column and line from a text file: BATCH

From Dev

Copy file from batch file's directory

From Dev

How to write into a Log file from the batch file?

From Dev

Batch file for starting powershell in a specific directory

From Dev

Batch Write to Text File with <Angle Brackets>

From Dev

Batch write text in txt file at line 17

From Dev

How to write, and use, a text batch command file

From Dev

iOS: How to write to a file at a specific directory in the project?

From Dev

Issue creating a text file from a batch file

From Dev

Batch file to read lines from text file

From Dev

Reading specific column of data from text file and write to another text file tcl

From Dev

Create a text file with batch with a specific path

From Dev

Create a text file with batch with a specific path

From Dev

How to write a matrix (read from one file) to another csv file in python with a specific output format

From Dev

Can I use a batch file to hilight a specific file format?

From Dev

text or sequence from the text file using batch?

From Java

How can I use a batch file to write to a text file?

From Dev

PowerShell: Run batch file and write output to text file

From Dev

Using Echo within a Batch File to write an IF Statement to a Text File

Related Related

  1. 1

    Batch file with spaces in variables/filenames in text file

  2. 2

    Batch File; List files in directory, only filenames?

  3. 3

    Batch file to process filenames ending in specific characters

  4. 4

    Create txt file from batch file with specific date format in it

  5. 5

    Batch file to delete specific text file from multiple locations

  6. 6

    Grab the filenames of the file from the directory and change as per string manipulation like String Concatination in BATCH script

  7. 7

    Filenames with . in batch file

  8. 8

    Read text file and write file from specific contents

  9. 9

    Batch file to not write variables in a text file

  10. 10

    Batch - Copy specific text from one file to another

  11. 11

    Copying a specific column and line from a text file: BATCH

  12. 12

    Copy file from batch file's directory

  13. 13

    How to write into a Log file from the batch file?

  14. 14

    Batch file for starting powershell in a specific directory

  15. 15

    Batch Write to Text File with <Angle Brackets>

  16. 16

    Batch write text in txt file at line 17

  17. 17

    How to write, and use, a text batch command file

  18. 18

    iOS: How to write to a file at a specific directory in the project?

  19. 19

    Issue creating a text file from a batch file

  20. 20

    Batch file to read lines from text file

  21. 21

    Reading specific column of data from text file and write to another text file tcl

  22. 22

    Create a text file with batch with a specific path

  23. 23

    Create a text file with batch with a specific path

  24. 24

    How to write a matrix (read from one file) to another csv file in python with a specific output format

  25. 25

    Can I use a batch file to hilight a specific file format?

  26. 26

    text or sequence from the text file using batch?

  27. 27

    How can I use a batch file to write to a text file?

  28. 28

    PowerShell: Run batch file and write output to text file

  29. 29

    Using Echo within a Batch File to write an IF Statement to a Text File

HotTag

Archive