0

I am working with the Informatica platform that only allows me to use batch files. I am currently producing a list of file names with the command dir /b /a-d

850_B_4545703_.txt
850_B_003029660_.txt
850_B_069029548_.txt
850_B_188789_.txt
850_C_ENT_1712865_.txt
850_C_ENT_1712871_.txt
850_C_1712877_.txt

But for Informatica to use this list to locate files I have to add path used in the flat file connection which is

\\jdeappp03\EDI\

So what I am trying to achieve is a batch file that will output the following:

\\jdeappp03\EDI\850_B_4545703_.txt
\\jdeappp03\EDI\850_B_003029660_.txt
\\jdeappp03\EDI\850_B_069029548_.txt
\\jdeappp03\EDI\850_B_188789_.txt
\\jdeappp03\EDI\850_C_ENT_1712865_.txt
\\jdeappp03\EDI\850_C_ENT_1712871_.txt
\\jdeappp03\EDI\850_C_1712877_.txt

I tried using dir /s/b *.txt but this give the absolute path which my setup of Informatica is not able to use to find the files.

Is there a way to get my desired result with a batch file?

  • does this help? https://superuser.com/questions/1767673/how-do-you-prepend-a-string-to-each-line-of-a-file-in-ms-dos?noredirect=1#comment2751444_1767673 It might put a carriage return after which might not be ideal. And it'd have to be the same string before each line. – barlop Feb 08 '23 at 23:04
  • In PowerShell, dir -attributes !directory | % { write-output ('\\blah\blah\' + $_.name) } or slightly simpler if adequate dir *.txt | % ... or in CMD powershell -c "{same}". (Powershell dir is actually an alias for get-childitem or its short form gci, which you can use if you wish. Similarly % is foreach-object.) – dave_thompson_085 Feb 09 '23 at 01:22
  • @dave_thompson_085 You wrote "slightly simpler if adequate dir *.txt | %" Doing dir *.txt | % gives "'%' is not recognized as an internal or external command" – barlop Feb 09 '23 at 08:05
  • @barlop I said "In Powershell" -- you're not using Powershell. Also, I said dir *.txt | % ... where ... is a special written form called an elllipsis that in this case means "fill out the same (command) string from the previous example, which is long enough I didn't want to waste space and effort repeating it" -- although this explanation has now wasted more space and effort than the ellipsis saved. – dave_thompson_085 Feb 09 '23 at 10:27

2 Answers2

2

You could use the following command in a batch file:

for /f "delims=" %%a in ('dir /b /a-d <PATH>') do (echo \\jdeappp03\EDI\%%a)

Using a for loop around the command allows you to iterate through its output and save it in the variable %%a. Everything you want to do during that iteration comes after do.

You only need parentheses after do if you want to use linebreaks for readability.

Use for /? in the Windows cmd to learn more about the for command.

  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. – Community Feb 09 '23 at 08:17
0

A shorter option would be:

for %%i in ("D:\Path\*.txt")do echo \\jdeappp03\EDI\%%~nxi
Io-oI
  • 8,193