why cd /d suddenly not working any longer in batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

why cd /d suddenly not working any longer in batch file

#1 Post by goodywp » 22 Aug 2022 11:49

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

miskox
Posts: 553
Joined: 28 Jun 2010 03:46

Re: why cd /d suddenly not working any longer in batch file

#2 Post by miskox » 22 Aug 2022 23:28

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

goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

Re: why cd /d suddenly not working any longer in batch file

#3 Post by goodywp » 23 Aug 2022 07:38

Here is the part of code

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
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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: why cd /d suddenly not working any longer in batch file

#4 Post by aGerman » 23 Aug 2022 07:49

Here is the log
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.

Steffen

goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

Re: why cd /d suddenly not working any longer in batch file

#5 Post by goodywp » 23 Aug 2022 08:00

aGerman wrote:
23 Aug 2022 07:49
Here is the log
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.

Steffen
But you can see when echo this drive and it did show up as F:\WKSP\CON2UPP
F:\WKSP\CON2UPP\T500B08951-0424_Lane7000_UPP_MOCKUP_00000

Anyway, I will ask our IT people....

OJBakker
Expert
Posts: 88
Joined: 12 Aug 2011 13:57

Re: why cd /d suddenly not working any longer in batch file

#6 Post by OJBakker » 23 Aug 2022 10:27

goodywp wrote:
23 Aug 2022 08:00

But you can see when echo this drive and it did show up as F:\WKSP\CON2UPP
F:\WKSP\CON2UPP\T500B08951-0424_Lane7000_UPP_MOCKUP_00000
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 ...
command.
Or check the errorlevel after the cd/d command.

miskox
Posts: 553
Joined: 28 Jun 2010 03:46

Re: why cd /d suddenly not working any longer in batch file

#7 Post by miskox » 23 Aug 2022 11:21

Or maybe add

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:
Saso

goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

Re: why cd /d suddenly not working any longer in batch file

#8 Post by goodywp » 23 Aug 2022 11:38

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: why cd /d suddenly not working any longer in batch file

#9 Post by aGerman » 23 Aug 2022 15:03

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

miskox
Posts: 553
Joined: 28 Jun 2010 03:46

Re: why cd /d suddenly not working any longer in batch file

#10 Post by miskox » 23 Aug 2022 23:46

One more thing: now I see it would be great to use

Code: Select all

dir f:\
(missing backslash)

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
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

goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

Re: why cd /d suddenly not working any longer in batch file

#11 Post by goodywp » 13 Sep 2022 13:39

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

Post Reply