Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
jeff.eisenberg
- Posts: 4
- Joined: 17 Apr 2015 14:55
#1
Post
by jeff.eisenberg » 17 Apr 2015 14:58
I'm trying to do a basic function in a batch file, but the parameter doesn't seem to get passed through. In the example below the parameter is "C:\Scantest". When I change it to not contain the characters ":\" it gets passed through. It seems that it has something to do with ":\". Any help is appreciated. You can easily test this yourself on a Windows workstation.
Code: Select all
CALL:DeleteFrom C:\Scanstest
:DeleteFrom
FORFILES -P %~1 -S -M *.* /D -1 /C "cmd /c DEL "@path""*
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#2
Post
by Ed Dyreen » 17 Apr 2015 15:46
Code: Select all
CALL :DeleteFrom "C:\Scanstest"
pause
exit 0
:DeleteFrom
:: (
parameters : '%~*'
parameter 1: '%~1'
:: )
exit /B 0
-
jeff.eisenberg
- Posts: 4
- Joined: 17 Apr 2015 14:55
#3
Post
by jeff.eisenberg » 17 Apr 2015 17:08
Thanks for replying but I'm not sure what that is supposed to mean.
Is that a correction to my code or does it just make a point on syntax?
Could you let me know specifically how my code should look to work correctly?
-
jeff.eisenberg
- Posts: 4
- Joined: 17 Apr 2015 14:55
#4
Post
by jeff.eisenberg » 17 Apr 2015 17:20
Disregard that last note. I think I have it working now. The script performs the function however, it returns a 2nd line with an error after it's already successful.
The script I have is:
Code: Select all
CALL :DeleteFrom "C:\Scanstest1"
:DeleteFrom
::(
FORFILES -P %~1 -S -M *.* /D -30 /C "cmd /c DEL @path"*
::)
The returned screen looks like this. You can see the last line shows an error after it's successful already:
C:\>CALL

eleteFrom "C:\Scanstest1"
C:\>FORFILES -P C:\Scanstest1 -S -M *.* /D -30 /C "cmd /c DEL @path"*
C:\>FORFILES -P -S -M *.* /D -30 /C "cmd /c DEL @path"*
ERROR: Invalid syntax. Value expected for '-P'.
Type "FORFILES /?" for usage.
C:\>
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#5
Post
by Ed Dyreen » 17 Apr 2015 18:47
I don't use forfiles but can only guess the parameter following -P needs to be enclosed in double quotes
or try
or Type "FORFILES /?" for usage.
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#6
Post
by Squashman » 17 Apr 2015 20:04
If you are using that code as is, it will execute TWICE. Once when the CALL executes and then again after it returns from the CALL. You need to either use the EXIT command after the CALL or a GOTO :EOF.
So essentially the second time it runs you have not specified a path with the /P option so it errors out.