Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch file to move and rename folder to a relative path

I have the following batch file in Windows 7 to be executed by a context menu shortcut. My aim is to move and rename a quote folder containing subfolders and files to a different path and rename it with the project number inserted when prompted.

for %%Q in (.) do set quotenumber=%%~nQ
for %%Y in (.\..) do set year=%%~nY
for %%C in (.\..\..\..) do set client=%%~nC
set /P projectnumber="Enter Project number>"
move "c:\myfiles\mainfiles\clients\%client%\quotes\%year%\%quotenumber%" "c:\myfiles\mainfiles\clients\%client%\projects\%year%\%projectnumber%"

I get the error "the process does not have access to the file because it is being used by another process". Can anybody tell me what I am doing wrong? I am not a programmer and cannot get this to work! Any help would be greatly appreciated.

like image 573
user2902883 Avatar asked Oct 20 '22 22:10

user2902883


1 Answers

Looking at your code I'm assuming that you;re executing it in c:\myfiles\mainfiles\clients\%client%\quotes\%year%\%quotenumber% dir. And in the last line you try to move the same dir to another place.Which is impossible because the dir is held by the script itself.Try this:

for %%Q in (.) do set quotenumber=%%~nQ
for %%Y in (.\..) do set year=%%~nY
for %%C in (.\..\..\..) do set client=%%~nC
set /P projectnumber="Enter Project number>"
cd ..
move "c:\myfiles\mainfiles\clients\%client%\quotes\%year%\%quotenumber%" "c:\myfiles\mainfiles\clients\%client%\projects\%year%\%projectnumber%"
like image 179
npocmaka Avatar answered Oct 29 '22 23:10

npocmaka