Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
mwatsondhs
- Posts: 9
- Joined: 13 Jan 2015 09:51
#1
Post
by mwatsondhs » 23 Jan 2015 07:47
When I run the code below it goes to the rename function but it never changes the directory.
P: is on a different machine and I think that this is the problem. Is this a permissions
problem or a coding problem? Any thoughts?
Thanks,
Mark
Code: Select all
@echo off
setlocal enabledelayedexpansion
FOR /F "delims=" %%G in ('dir sls316*.pdf /a-d /b /od') do set "newest=%%~G"
copy "%newest%" p:\"BCS Reports"\Temp
call :rename
:rename
echo in rename function
cd p:\"BCS Reports"\Temp
call rename.bat
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 23 Jan 2015 07:57
H:\>cd /?
Displays the name of or changes the current directory.
CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
.. Specifies that you want to change to the parent directory.
Type CD drive: to display the current directory in the specified drive.
Type CD without parameters to display the current drive and directory.
Use the /D switch to change current drive in addition to changing current
directory for a drive.
And put the quotes around the full path.
-
mwatsondhs
- Posts: 9
- Joined: 13 Jan 2015 09:51
#3
Post
by mwatsondhs » 23 Jan 2015 08:17
I tried cd and chdir with and without /D and it still doesn't work.
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#4
Post
by Squashman » 23 Jan 2015 08:43
C:\Foo.bat
Code: Select all
@echo off
setlocal enabledelayedexpansion
echo I am in the first batch file
call :rename
pause
GOTO :EOF
:rename
echo in rename function
cd /D "H:\BCS Reports\Temp"
call rename.bat
H:\BCS Reports\Temp\rename.bat
Code: Select all
@echo off
echo I am in the rename bat file.
output
Code: Select all
I am in the first batch file
in rename function
I am in the rename bat file.
Press any key to continue . . .
-
ShadowThief
- Expert
- Posts: 1167
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
#5
Post
by ShadowThief » 23 Jan 2015 09:00
Is P: a mapped network drive? I seem to recall something about needing to re-map the drive at the start of the script.
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#6
Post
by Squashman » 23 Jan 2015 09:26
If the CD command did not work you would see this as an error.
Code: Select all
The system cannot find the drive specified.
Then because the CD command did not work the CALL to the 2nd batch file would produce this error.
Code: Select all
The syntax of the command is incorrect.
-
mwatsondhs
- Posts: 9
- Joined: 13 Jan 2015 09:51
#7
Post
by mwatsondhs » 23 Jan 2015 10:09
Squashman,
The pause did the trick. I guess it was calling the other batch file before it got a chance to switch
directories. Thanks for all of your help. I owe you. If you ever have and SQL questions let me know.
Mark
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#8
Post
by Squashman » 23 Jan 2015 10:33
mwatsondhs wrote:Squashman,
The pause did the trick. I guess it was calling the other batch file before it got a chance to switch
directories.
Mark
NOT POSSIBLE.
Batch is sequential processing. It does not execute the next command until the previous command completes.
The pause was put in so you could read all the messages on the screen.