The process cannot access the file because it is being used by another process

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

The process cannot access the file because it is being used by another process

#1 Post by goodywp » 03 Dec 2020 11:05

Hi all,

I have a script to output the folders list and their underneath file version into a file called list.txt

Code: Select all

@echo off

for /f "tokens=1-4 delims=, " %%A in (C:\Users\wyxy\Test\list2_UPP.txt) do call :indexlist "%%A" %%B %%C %%D 

EXIT /B %ERRORLEVEL% 

:indexlist
set snfld=%~1
set snfld=%snfld:"=%

set snfile=%~2
set snfileND=%snfile:~-3%

set snprefix=%snfile:~0,6%
set snver=%snfile:~6,4%

set snfile2=%~2
set snprefix2=%snfile2:~0,10%
set snver2=%snfile2:~10,6%

:::::::::::::::::::::::::::::
::Two components for AppleVAS
:::::::::::::::::::::::::::::
if "%snprefix%"=="844941" (
echo %snfld%>>list.txt
echo 	LIBLEGAPPV 			 			Version: %snver%>>list.txt
	)
	
if "%snprefix%"=="844943" (
echo 	LIBLEGOSE 		     			Version: %snver%>>list.txt
	)

:::::::::::::::::::::::::::::
::AppleVasEssentials 
:::::::::::::::::::::::::::::	
if "%snprefix2%"=="9992047406" (
echo %snfld%>>list.txt
echo 	vasApple 			 			Version: %snver2%>>list.txt
	)

:::::::::::::::::::::::::::::
::NAR KIA
:::::::::::::::::::::::::::::
if "%snprefix%"=="829500" (
	if "%snfileND%"=="P3A" (
echo %snfld%>>list.txt
echo 	929500				 			Version: %snver%>>list.txt
		)
	)

:::::::::::::::::::::::::::::
::NAR TSA
:::::::::::::::::::::::::::::
if "%snprefix%"=="829501" (
	if "%snfileND%"=="P3A" (
echo %snfld%>>list.txt
echo 	829501				 			Version: %snver%>>list.txt
		)
	)


EXIT /B 0

using the above script I can have the output file list.txt as below
  • LIBLEGAPPV Version: 0306
    LIBLEGOSE Version: 0312
    AppleVasEssentials
    vasApple Version: 010400
    NAR KIA
    929500 Version: 0627
    NAR TSA
    829501 Version: 0627
Now the problem is after inserting a function to read some info which will be added onto KIA and TSA components. It shall looks like below:
  • LIBLEGAPPV Version: 0306
    LIBLEGOSE Version: 0312
    AppleVasEssentials
    vasApple Version: 010400
    NAR KIA
    929500 Version: 0627 T501-08680-0103 T501-08699-0100 0501-08690-0100 T503-08961-0100
    NAR TSA
    829501 Version: 0627 T501-08699-0100 0501-08690-0100
I modified the above script to add as below

Code: Select all

@echo off

for /f "tokens=1-4 delims=, " %%A in (C:\Users\wyxy\Test\list2_UPP.txt) do call :indexlist "%%A" %%B %%C %%D 

EXIT /B %ERRORLEVEL% 

:indexlist
set snfld=%~1
set snfld=%snfld:"=%

set snfile=%~2
set snfileND=%snfile:~-3%

set snprefix=%snfile:~0,6%
set snver=%snfile:~6,4%

set snfile2=%~2
set snprefix2=%snfile2:~0,10%
set snver2=%snfile2:~10,6%

:::::::::::::::::::::::::::::
::Two components for AppleVAS
:::::::::::::::::::::::::::::
if "%snprefix%"=="844941" (
echo %snfld%>>list.txt
echo 	LIBLEGAPPV 			 			Version: %snver%>>list.txt
	)
	
if "%snprefix%"=="844943" (
echo 	LIBLEGOSE 		     			Version: %snver%>>list.txt
	)

:::::::::::::::::::::::::::::
::AppleVasEssentials 
:::::::::::::::::::::::::::::	
if "%snprefix2%"=="9992047406" (
echo %snfld%>>list.txt
echo 	vasApple 			 			Version: %snver2%>>list.txt
	)

:::::::::::::::::::::::::::::
::NAR KIA
:::::::::::::::::::::::::::::
for /f "tokens=1-7 delims=," %%A in (C:\CA_MOCKUP\Tetra_Schemes\temp\scheme\829500_scheme_data.cfg) do (set str1=%%A)
set "schKIA=%str1:~7,200%"
if "%snprefix%"=="829500" (

	if "%snfileND%"=="P3A" (
echo %snfld%>>list.txt
echo 	929500				 			Version: %snver%	(%schKIA%) >>list.txt
		)
	)

:::::::::::::::::::::::::::::
::NAR TSA
:::::::::::::::::::::::::::::
for /f "tokens=1-7 delims=," %%A in (C:\CA_MOCKUP\Tetra_Schemes\temp\scheme\829501_scheme_data.cfg) do (set str1=%%A)
set "schTSA=%str1:~7,200%"


if "%snprefix%"=="829501" (
	if "%snfileND%"=="P3A" (
echo %snfld%>>list.txt
echo 	829501				 			Version: %snver%         (%schTSA%)>>list.txt
		)
	)


EXIT /B 0

Now it always complain this message
The process cannot access the file because it is being used by another process
And it will not correctly add the info I needed.
Need your input...

Thanks
Last edited by goodywp on 03 Dec 2020 11:51, edited 1 time in total.

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

Re: The process cannot access the file because it is being used by another process

#2 Post by aGerman » 03 Dec 2020 11:22

I'm a little lost in this weird code indentations when I try to understand it. But what I can make out is that you have some multiline blocks enclosed into parentheses. And in those blocks you're trying to redirect text that contains parentheses. Make sure that you always escape the closing parenthesis in your ECHO redirections because elsewise they are treated as to belong to the code.
Maybe there are still other problems, but that's from where you can start...

Steffen

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

Re: The process cannot access the file because it is being used by another process

#3 Post by goodywp » 03 Dec 2020 12:56

Thanks Steffen! After I added ^ before the ) it works as expected!

Code: Select all

@echo off

for /f "tokens=1-4 delims=, " %%A in (C:\Users\wyxy\Test\list2_UPP.txt) do call :indexlist "%%A" %%B %%C %%D 

EXIT /B %ERRORLEVEL% 

:indexlist
set snfld=%~1
set snfld=%snfld:"=%

set snfile=%~2
set snfileND=%snfile:~-3%

set snprefix=%snfile:~0,6%
set snver=%snfile:~6,4%

set snfile2=%~2
set snprefix2=%snfile2:~0,10%
set snver2=%snfile2:~10,6%

:::::::::::::::::::::::::::::
::Two components for AppleVAS
:::::::::::::::::::::::::::::
if "%snprefix%"=="844941" (
echo %snfld%>>list.txt
echo 	LIBLEGAPPV 			 			Version: %snver%>>list.txt
	)
	
if "%snprefix%"=="844943" (
echo 	LIBLEGOSE 		     			Version: %snver%>>list.txt
	)

:::::::::::::::::::::::::::::
::AppleVasEssentials 
:::::::::::::::::::::::::::::	
if "%snprefix2%"=="9992047406" (
echo %snfld%>>list.txt
echo 	vasApple 			 			Version: %snver2%>>list.txt
	)

:::::::::::::::::::::::::::::
::NAR KIA
:::::::::::::::::::::::::::::
<C:\CA_MOCKUP\Tetra_Schemes\temp\scheme\829500_scheme_data.cfg set /p str1=
set "schKIA=%str1:~7,200%"
if "%snprefix%"=="829500" (
	if "%snfileND%"=="P3A" (
echo %snfld%>>list.txt
echo 	929500				 			Version: %snver%	(%schKIA%^) >>list.txt
		)
	)

:::::::::::::::::::::::::::::
::NAR TSA
:::::::::::::::::::::::::::::
<C:\CA_MOCKUP\Tetra_Schemes\temp\scheme\829501_scheme_data.cfg set /p str1=
set "schTSA=%str1:~7,200%"
if "%snprefix%"=="829501" (
	if "%snfileND%"=="P3A" (
echo %snfld%>>list.txt
echo 	829501				 			Version: %snver%         (%schTSA%^)>>list.txt
		)
	)


EXIT /B 0


Post Reply