0

I am running into an issue here on Windows 10. I am trying to set an environment variable within the batch file using a for ... in ... do, but it never finds the file folder I am looking for.

example:

cd \temp
  for /f "delims=" %%a in ('dir /b /ad somefolder*') do set somefolder=%%a
cd \temp\%somefolder%\microsoft

When run as an administrator I will get an error: file not found. When run as non-admin it functions properly. This can only be run as a batch while using DISM.

aschipfl
  • 103
  • 5
Mike
  • 1
  • Welcome to ServerFault. I've edited your question to format the code to make it easier to read. Once the edit appears, please confirm that I didn't inadvertently change the code. – Doug Deden Jun 28 '19 at 19:41
  • Does the name of the folder you are searching really begin with somefolder? and is it placed in the temp directory of the root directory of the current drive (whatever it is)? – aschipfl Jul 01 '19 at 15:41

1 Answers1

0

In your example, "somefolder" is a relative folder path.

When running as admin, you have a different default directory. If you use an absolute path, it should work fine.

iPaulo
  • 427
  • actually %somefolder% is an absolute path as the folder is present as I made the folder. The C:\temp is off the root which shows it's absolute.I am only searching for the folder name as it changes monthly. – Mike Jun 28 '19 at 17:57
  • When you are running under DISM, is \temp a valid way to refer to c:\temp? Have you tried "cd /d c:\temp"? – iPaulo Jun 28 '19 at 21:45
  • Check out the last comment in https://stackoverflow.com/questions/27872799/dism-fails-in-bat-but-runs-fine-from-command-prompt. I'm not sure how you are invoking this script but it seems like it might help. – iPaulo Jun 28 '19 at 21:49
  • iPaulo you hit the nail on the head by referencing the other article. This loop is no functioning properly. – Mike Jul 03 '19 at 14:54
  • That's good. Did it help though? :) Are you using this loop in a similar way, calling DISM to mount the directory you are trying to loop through? It might be useful to post more of your script to see the context. – iPaulo Jul 03 '19 at 22:40