0

I understand that this question has been asked multiple times. But even after using pushd and popd, I am unable to resolve this at my end. My code is specified below. I could see multiple network drives under My Computer getting mapped, but I would like to have only 1 drive getting mapped for each for loop iteration. Please let me know what am I doing wrong?

@echo off

for /d %%a in (\\MIGRATE01\content\*) do (
   pushd "%%a"
   set x=%%~nxa
   echo no_match=E:\Nomatch\%%~nxa\)>"E:\Testing\prop_file1.txt"
   E:\oracle1_run.bat --context=Default --context_param prop_file=E:\Testing\prop_file1.txt
   popd
)
popd
del "E:\Testing\prop_file1.txt"
vsingh
  • 125
  • 1
  • 2
  • 16
  • What makes you think that more than one (1) drive is mapped on each iteration of the loop? Are you thinking that the mapped drive letter will be `E:`? What makes you think that? BTW, the `popd` outside the loop is unmatched with a `pushd`. – lit Oct 03 '19 at 20:36
  • I thought that multiple drives are getting mapped because even before executing the code in E:\oracle1_run.bat, I could see multiple drives under my computer. Also, no, I am not assuming it to be E. E is already a working drive where I have one of the bat file which I am trying to execute. I tried removing the popd which is out of for loop and execute. Somehow, now only the last folder gets executed. – vsingh Oct 03 '19 at 20:41
  • Unless there is something inside `E:\oracle1_run.bat` that uses it, this code does not appear to do anything with the drive mapped by `pushd`. There is no use of `!x!` anywhere. BTW, to use the variable `x`, you need delayed expansion and use ! around the variable name. – lit Oct 03 '19 at 20:54
  • Why not doing `pushd "\\MIGRATE01\content" || exit /B 1` before the loop, then looping like `for /D %%a in (*) do ( ... )`, and then doing `popd`? And put `call` in front of `E:\oracle1_run.bat ...`... – aschipfl Oct 03 '19 at 22:07
  • 1
    What was wrong with the code in [the answer I gave you yesterday](https://stackoverflow.com/a/58206602/6738015)? If it was necessary, to run the batch file with each directory in `\\MIGRATE01\content` as the current directory, you'd `PushD "\\MIGRATE01\content"` before the `for` loop use `*` inside your `for` loop and use standard `CD "%%A"`/`CD ..` or `PushD "%%A"`/`PopD`, you'll finally `PopD` after the `for` loop. – Compo Oct 04 '19 at 00:30

0 Answers0