why cd /d suddenly not working any longer in batch file
Moderator: DosItHelp
why cd /d suddenly not working any longer in batch file
Hi All,
Our company recently implement a lot of security measures.
One of the noticed issue is that I need add timeout /t n to make the scripts working. Otherwise it shall complain as below:
The process cannot access the file because it is being used by another process.
Now I had another issue as below:
cd /d %NEW_PACKAGE_BASE_PATH%\%NEW_PACKAGE_NAME%
it was working fine before, but now complain "The system cannot find the path specified."
But when I manually run this above command in cmd and it works. But the same command in batch file not working...
Any experience or thought you have like this case?
Thanks
Our company recently implement a lot of security measures.
One of the noticed issue is that I need add timeout /t n to make the scripts working. Otherwise it shall complain as below:
The process cannot access the file because it is being used by another process.
Now I had another issue as below:
cd /d %NEW_PACKAGE_BASE_PATH%\%NEW_PACKAGE_NAME%
it was working fine before, but now complain "The system cannot find the path specified."
But when I manually run this above command in cmd and it works. But the same command in batch file not working...
Any experience or thought you have like this case?
Thanks
Re: why cd /d suddenly not working any longer in batch file
It would be good to provide more info (even anonimized data). First idea: add " before and after. Add ECHO ON so you could see the complete CD command.
Saso
Saso
Re: why cd /d suddenly not working any longer in batch file
Here is the part of code
Here is the log
build 23-Aug-2022 09:28:17 C:\CA_CONVERT\Scripts\Updating current directory
build 23-Aug-2022 09:28:17 F:\WKSP\CON2UPP\T500B08951-0424_Lane7000_UPP_MOCKUP_00000
error 23-Aug-2022 09:28:17 The system cannot find the path specified.
build 23-Aug-2022 09:28:17 286
build 23-Aug-2022 09:28:17 C:\CA_CONVERT\Scripts\Updating again to see the directory
Code: Select all
ping -n 15 127.0.0.1 >NUL
echo %CD% current directory
echo %NEW_PACKAGE_BASE_PATH%\%NEW_PACKAGE_NAME%
cd /d %NEW_PACKAGE_BASE_PATH%\%NEW_PACKAGE_NAME%
::pushd %NEW_PACKAGE_BASE_PATH%\%NEW_PACKAGE_NAME%
echo 286
echo %CD% again to see the directory
build 23-Aug-2022 09:28:17 C:\CA_CONVERT\Scripts\Updating current directory
build 23-Aug-2022 09:28:17 F:\WKSP\CON2UPP\T500B08951-0424_Lane7000_UPP_MOCKUP_00000
error 23-Aug-2022 09:28:17 The system cannot find the path specified.
build 23-Aug-2022 09:28:17 286
build 23-Aug-2022 09:28:17 C:\CA_CONVERT\Scripts\Updating again to see the directory
Re: why cd /d suddenly not working any longer in batch file
Curious: What did create the log? I'm asking because it indicates that you may run it somehow automated. Maybe from within a sheduled task. If this is the case and the task is running in a different account, it is very likely that network drives (like F:) are not mapped for this account.Here is the log
Steffen
Re: why cd /d suddenly not working any longer in batch file
But you can see when echo this drive and it did show up as F:\WKSP\CON2UPPaGerman wrote: ↑23 Aug 2022 07:49Curious: What did create the log? I'm asking because it indicates that you may run it somehow automated. Maybe from within a sheduled task. If this is the case and the task is running in a different account, it is very likely that network drives (like F:) are not mapped for this account.Here is the log
Steffen
F:\WKSP\CON2UPP\T500B08951-0424_Lane7000_UPP_MOCKUP_00000
Anyway, I will ask our IT people....
Re: why cd /d suddenly not working any longer in batch file
The echo is no check for existence of a file/folder. The echo is just echoing the value you set in the variables.
If you want to check if a file/folder does exist use the
Code: Select all
if exist ...
Or check the errorlevel after the cd/d command.
Re: why cd /d suddenly not working any longer in batch file
Or maybe add
Saso
Code: Select all
echo DIR %NEW_PACKAGE_BASE_PATH%\%NEW_PACKAGE_NAME%
dir %NEW_PACKAGE_BASE_PATH%\%NEW_PACKAGE_NAME%
echo DIR F:
REM F: because you know it
dir f:
Re: why cd /d suddenly not working any longer in batch file
Added suggested code to check got below results:
build 23-Aug-2022 13:34:49 DIR F:\WKSP\CON2UPP\T500B08951-0425_Lane7000_UPP_MOCKUP_00000
build 23-Aug-2022 13:34:49 Volume in drive F is DATA
build 23-Aug-2022 13:34:49 Volume Serial Number is 740C-448B
build 23-Aug-2022 13:34:49
build 23-Aug-2022 13:34:49 Directory of F:\WKSP\CON2UPP
build 23-Aug-2022 13:34:49
error 23-Aug-2022 13:34:49 File Not Found
build 23-Aug-2022 13:34:49 DIR F:
build 23-Aug-2022 13:34:49 Volume in drive F is DATA
build 23-Aug-2022 13:34:49 Volume Serial Number is 740C-448B
build 23-Aug-2022 13:34:49
build 23-Aug-2022 13:34:49 Directory of F:\bamboo-build\build-dir\TET-CON2UPP-BCORE
build 23-Aug-2022 13:34:49
build 23-Aug-2022 13:34:49 2022-07-28 01:41 PM <DIR> .
build 23-Aug-2022 13:34:49 2022-07-28 01:41 PM <DIR> ..
build 23-Aug-2022 13:34:49 2021-03-30 12:15 PM <DIR> PROFILE
build 23-Aug-2022 13:34:49 2022-07-28 01:41 PM <DIR> WKSP
build 23-Aug-2022 13:34:49 0 File(s) 0 bytes
build 23-Aug-2022 13:34:49 4 Dir(s) 135,613,231,104 bytes free
build 23-Aug-2022 13:34:49 DIR F:\WKSP\CON2UPP\T500B08951-0425_Lane7000_UPP_MOCKUP_00000
build 23-Aug-2022 13:34:49 Volume in drive F is DATA
build 23-Aug-2022 13:34:49 Volume Serial Number is 740C-448B
build 23-Aug-2022 13:34:49
build 23-Aug-2022 13:34:49 Directory of F:\WKSP\CON2UPP
build 23-Aug-2022 13:34:49
error 23-Aug-2022 13:34:49 File Not Found
build 23-Aug-2022 13:34:49 DIR F:
build 23-Aug-2022 13:34:49 Volume in drive F is DATA
build 23-Aug-2022 13:34:49 Volume Serial Number is 740C-448B
build 23-Aug-2022 13:34:49
build 23-Aug-2022 13:34:49 Directory of F:\bamboo-build\build-dir\TET-CON2UPP-BCORE
build 23-Aug-2022 13:34:49
build 23-Aug-2022 13:34:49 2022-07-28 01:41 PM <DIR> .
build 23-Aug-2022 13:34:49 2022-07-28 01:41 PM <DIR> ..
build 23-Aug-2022 13:34:49 2021-03-30 12:15 PM <DIR> PROFILE
build 23-Aug-2022 13:34:49 2022-07-28 01:41 PM <DIR> WKSP
build 23-Aug-2022 13:34:49 0 File(s) 0 bytes
build 23-Aug-2022 13:34:49 4 Dir(s) 135,613,231,104 bytes free
Re: why cd /d suddenly not working any longer in batch file
My question is still whether or not the script is running in another account. Might also be the case that this acoount has no access to the folder. (Wouldn't be the first time that error messages are missleading.)
Steffen
Steffen
Re: why cd /d suddenly not working any longer in batch file
One more thing: now I see it would be great to use
(missing backslash)
And what Steffen wrote.
And from what you wrote:
Above you can see that directory T500B08951-0425_Lane7000_UPP_MOCKUP_00000 does not exist. So if this is a file then you can't move to this directory because it is a file. If this is a directory then you should create one (or as Steffen wrote: if it was written by another account you might not have access to it).
So I made some tests:
1.) if I do a CD to a 'file' I get this error:
The directory name is invalid.
2.) if I do a CD to a folder that does not exist I get this error:
The system cannot find the path specified.
This would mean (with your original post) that the folder T500B08951-0425_Lane7000_UPP_MOCKUP_00000 does not exist (reasons written above).
Saso
Code: Select all
dir f:\
And what Steffen wrote.
And from what you wrote:
Code: Select all
DIR F:\WKSP\CON2UPP\T500B08951-0425_Lane7000_UPP_MOCKUP_00000
build 23-Aug-2022 13:34:49 Directory of F:\WKSP\CON2UPP
error 23-Aug-2022 13:34:49 File Not Found
So I made some tests:
1.) if I do a CD to a 'file' I get this error:
The directory name is invalid.
2.) if I do a CD to a folder that does not exist I get this error:
The system cannot find the path specified.
This would mean (with your original post) that the folder T500B08951-0425_Lane7000_UPP_MOCKUP_00000 does not exist (reasons written above).
Saso
Re: why cd /d suddenly not working any longer in batch file
Thanks all!
Your comments are correct. Someone temporary made a sub folder called su before this folder, ie. ..\su\T500B08951-0425_Lane7000_UPP_MOCKUP_00000 then this su folder removed in the process. As long as this variable su added in the end of the scripts as a variable input then re-run the scripts it works now.
Thanks
Your comments are correct. Someone temporary made a sub folder called su before this folder, ie. ..\su\T500B08951-0425_Lane7000_UPP_MOCKUP_00000 then this su folder removed in the process. As long as this variable su added in the end of the scripts as a variable input then re-run the scripts it works now.
Thanks