.bat File Help


Recommended Posts

Can someone tell me why this is not working.... Heres the code, in case the .bat doesn't make it

ren C:\Program Files\DP Desktop\DPDeskTop.exe DPDeskTop.ex_

Pause

Copy x:\DDR\Public\DPDesktop.exe C:\Program Files\DP Desktop\DPDeskTop.exe

pause

Says "Invalid Syntax"

Thanks

Link to comment
Share on other sites

parameters are separated by a space unless you put quotes around it... ie. in the first line you give ren four parameters instead of two, same in the third line (copy). Haven't tested this but i think it should work:

ren "C:\Program Files\DP Desktop\DPDeskTop.exe" DPDeskTop.ex_

Pause

Copy x:\DDR\Public\DPDesktop.exe "C:\Program Files\DP Desktop\DPDeskTop.exe"

pause

Link to comment
Share on other sites

Another quick question, is there a way to report an error and abort if the file is not initially found in the first line? On Abort, I would like it to say "the program appears to not be found on this system", pause, then exit.... :blink: Would also like to add a brief description line at the beginning that just displays text and asks if you would like to continue with the upgrade....

Thanks

Link to comment
Share on other sites

Yup:

if not exist "C:\Program Files\DP Desktop\DPDeskTop.exe" (

echo.The program appears to not be found on this system&pause>nul&goto:eof)

Also, you can add @echo off to the beginning of the file to make it stop reading out each line.

As for the upgrade thing, you can use echo and pause like this:

echo Welcome to my installation

echo Press any key to continue with installation

pause>nul

Link to comment
Share on other sites

if exist "c:\program files\someprogram\app.exe" goto exists

echo File doesn't exist

pause

goto exit

:exists

echo File exists

rem *** etc. ***

:exit

sth like that?

for the choice thingy... from DOS 5.0 or 6.0 on there was choice.com (or was it .exe?) that you could use with if errorlevel, ie. it's also included in win9x; but i don't think NT supports it. SET took over this job iirc. check its command line help (set /?)

Link to comment
Share on other sites

Man thanks guys, I am really close, have just one more thing:

Heres where I am:

@echo Welcome to the Datapass Upgrade for Nov 2002

@echo Press any key to begin the upgrade process

if exist "c:\program files\DP Desktop\DPDesktop.exe" goto exists

@echo It appears that Datapass is not installed on this system

pause

goto exit

:exists

ren "C:\Program Files\DP Desktop\DPDeskTop.exe" DPDeskTop.ex_

Pause

Copy x:\DDR\Public\DPDesktop.exe "C:\Program Files\DP Desktop\DPDeskTop.exe"

pause

:exit

Runs and exits appropriately, but after the first two lines are displayed, It lists this:

X:\DDR\Public>if exist "c:\program files\DP Desktop\DPDesktop.exe" goto exists

It appears that Datapass is not installed on this system

X:\DDR\Public>Pause

Press any key to continue ...

Just like that! Is there a way to remove the top part, and only display the text lines below it?

Thanks one last time.... :cry:

Link to comment
Share on other sites

Man, you guys are good....Really enjoy and appreciate the help...Can you tell me if it's possible to perform a search of the "C" drive looking for the particular file and then "ren" all of the instances of file, then copying the new file into their folders......

Link to comment
Share on other sites

from the "for" command line help (for /?):

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

   Walks the directory tree rooted at [drive:]path, executing the FOR

   statement in each directory of the tree.  If no directory

   specification is specified after /R then the current directory is

   assumed.  If set is just a single period (.) character then it

   will just enumerate the directory tree.

I dunno what you mean with "their folders" but for the rest this should work:

for /R c:\ %%a in (.) do if exist %%a\myfile.ext ren %%a\myfile.ext newname.txt

note that it might take a long time for this statement to complete. it's the best solution i could come up with right now, though there are probably better and faster ones (possibly involving dir /b and a temporary file or some other, probably nested, "for" statements).

Link to comment
Share on other sites

Can you tell me if it's possible to perform a search of the "C" drive looking for the particular file and then "ren" all of the instances of file, then copying the new file into their folders......

I wouldn't recommend this for two reasons:

1) It's slow! Do a dir/b/s \ in command prompt and see what I mean.

2) If they have another unrelated file named with the name you're searching for and you rename it, it could ruin something

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.