0

I am trying to open Excel files one by one in a particular folder (mentioned in code) through a batch file. But I am getting error as the file extension is not read fully by the code or machine.

Eg: I have a excel file in dir path "D:\Eplans" "EP101.xlsx".

While running code error comes as :

could not find the file "EP101.xl

Code:

chdir D:\Eplans
dir /b *.xlsx >  list_dwg.txt
for /f "delims=<tab><space>" %%f in (list_dwg.txt) do (start "D:\Program Files\Microsoft  Office\Office12\EXCEL.exe" %%f)

PS: I am just a newbie to the batch programming.

Andre Silva
  • 4,782
  • 9
  • 52
  • 65
  • If you check the content of `list_dwg.txt`, do the file names look OK, or they are missing the "sx" in the extension? Have you tried removing the `"delims="` part and see if your code works? – Laf Sep 10 '14 at 18:57
  • I don't see how it's possible for this error to come up from the code you gave. But the problem probably is that `chdir D:\Eplans` needs to be `chdir /D D:\Eplans`. – indiv Sep 10 '14 at 19:03
  • You may also need double quotes around the final `%%f`, as in `start "D:\Program Files\Microsoft Office\Office12\Excel.exe" "%%f"` to handle any spaces in the filename. – Ken White Sep 10 '14 at 19:16
  • See this: http://stackoverflow.com/questions/9250567/batch-file-to-execute-all-files-in-a-folder – Santiago Benoit Sep 10 '14 at 20:42
  • I found a solution for the time being here in stack flow. I had to remove "delims=" and substitute it with "usebackq". Now it is working fine. Thanks for your time. – Ajay Krishnan Sep 13 '14 at 03:35

1 Answers1

0

i'd just say

for %%a in (d:\eplans\*.xlsx) do start "%%a"

i assume xlsx files are associated with excel anyway, the txt file is unneccesary, and %%a will contain the full path.

ths
  • 2,858
  • 1
  • 16
  • 21