PC Review


Reply
Thread Tools Rate Thread

Batch file works in command line but not as a batch

 
 
Danger
Guest
Posts: n/a
 
      1st Feb 2008
This batch file is a simple rename of a file folder
I can run it on the command line and it works, In a batch file it can not
find the file name.

the code
_____________

C:
cd C:\Documents and Settings\%USERNAME%\Application Data\Research In
Motion\BlackBerry
IF Exist intellisync-old (rd /s /q intellisync-old) ELSE (ECHO SUCESS)
PAUSE
ren intellisync intellisync-old
pause

___________________

the result


C:\Documents and Settings\Administrator\Application Data\Research In
Motion\Blac
kBerry>IF Exist intellisync-old (rd /s /q intellisync-old ) ELSE (ECHO
SUCESS )

SUCESS

C:\Documents and Settings\Administrator\Application Data\Research In
Motion\Blac
kBerry>PAUSE
Press any key to continue . . .

C:\Documents and Settings\Administrator\Application Data\Research In
Motion\Blac
kBerry>ren intellisync intellisync-old
The system cannot find the file specified.

C:\Documents and Settings\Administrator\Application Data\Research In
Motion\Blac
kBerry>pause
Press any key to continue . . .

_____________________________________

the file folder with the correct name is in the correct dir

Thank you in advance,
 
Reply With Quote
 
 
 
 
Bob I
Guest
Posts: n/a
 
      1st Feb 2008
You need quotes around path names with spaces.

Danger wrote:

> This batch file is a simple rename of a file folder
> I can run it on the command line and it works, In a batch file it can not
> find the file name.
>
> the code
> _____________
>
> C:
> cd C:\Documents and Settings\%USERNAME%\Application Data\Research In
> Motion\BlackBerry
> IF Exist intellisync-old (rd /s /q intellisync-old) ELSE (ECHO SUCESS)
> PAUSE
> ren intellisync intellisync-old
> pause
>
> ___________________
>
> the result
>
>
> C:\Documents and Settings\Administrator\Application Data\Research In
> Motion\Blac
> kBerry>IF Exist intellisync-old (rd /s /q intellisync-old ) ELSE (ECHO
> SUCESS )
>
> SUCESS
>
> C:\Documents and Settings\Administrator\Application Data\Research In
> Motion\Blac
> kBerry>PAUSE
> Press any key to continue . . .
>
> C:\Documents and Settings\Administrator\Application Data\Research In
> Motion\Blac
> kBerry>ren intellisync intellisync-old
> The system cannot find the file specified.
>
> C:\Documents and Settings\Administrator\Application Data\Research In
> Motion\Blac
> kBerry>pause
> Press any key to continue . . .
>
> _____________________________________
>
> the file folder with the correct name is in the correct dir
>
> Thank you in advance,


 
Reply With Quote
 
Danger
Guest
Posts: n/a
 
      1st Feb 2008
Sorry The change to directory works fine. you can see that below in the
output example. Thanks however.

"Bob I" wrote:

> You need quotes around path names with spaces.
>
> Danger wrote:
>
> > This batch file is a simple rename of a file folder
> > I can run it on the command line and it works, In a batch file it can not
> > find the file name.
> >
> > the code
> > _____________
> >
> > C:
> > cd C:\Documents and Settings\%USERNAME%\Application Data\Research In
> > Motion\BlackBerry
> > IF Exist intellisync-old (rd /s /q intellisync-old) ELSE (ECHO SUCESS)
> > PAUSE
> > ren intellisync intellisync-old
> > pause
> >
> > ___________________
> >
> > the result
> >
> >
> > C:\Documents and Settings\Administrator\Application Data\Research In
> > Motion\Blac
> > kBerry>IF Exist intellisync-old (rd /s /q intellisync-old ) ELSE (ECHO
> > SUCESS )
> >
> > SUCESS
> >
> > C:\Documents and Settings\Administrator\Application Data\Research In
> > Motion\Blac
> > kBerry>PAUSE
> > Press any key to continue . . .
> >
> > C:\Documents and Settings\Administrator\Application Data\Research In
> > Motion\Blac
> > kBerry>ren intellisync intellisync-old
> > The system cannot find the file specified.
> >
> > C:\Documents and Settings\Administrator\Application Data\Research In
> > Motion\Blac
> > kBerry>pause
> > Press any key to continue . . .
> >
> > _____________________________________
> >
> > the file folder with the correct name is in the correct dir
> >
> > Thank you in advance,

>
>

 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      1st Feb 2008

"Danger" <(E-Mail Removed)> wrote in message
news:4069A1AB-B395-4E74-B411-(E-Mail Removed)...
> This batch file is a simple rename of a file folder
> I can run it on the command line and it works, In a batch file it can not
> find the file name.
>
> the code
> _____________
>
> C:
> cd C:\Documents and Settings\%USERNAME%\Application Data\Research In
> Motion\BlackBerry
> IF Exist intellisync-old (rd /s /q intellisync-old) ELSE (ECHO SUCESS)
> PAUSE
> ren intellisync intellisync-old
> pause
>
> ___________________
>
> the result
>
>
> C:\Documents and Settings\Administrator\Application Data\Research In
> Motion\Blac
> kBerry>IF Exist intellisync-old (rd /s /q intellisync-old ) ELSE (ECHO
> SUCESS )
>
> SUCESS
>
> C:\Documents and Settings\Administrator\Application Data\Research In
> Motion\Blac
> kBerry>PAUSE
> Press any key to continue . . .
>
> C:\Documents and Settings\Administrator\Application Data\Research In
> Motion\Blac
> kBerry>ren intellisync intellisync-old
> The system cannot find the file specified.
>
> C:\Documents and Settings\Administrator\Application Data\Research In
> Motion\Blac
> kBerry>pause
> Press any key to continue . . .
>
> _____________________________________
>
> the file folder with the correct name is in the correct dir
>
> Thank you in advance,


Your batch file tests for the existence of "intellisync.old". It does
not test for the existence of "intellisync", hence the attempt to
rename this folder will fail if the folder does not exist. Nothing
magic there.

About the quotes, missing or otherwise: You ***should***
always surround file/folder names with quotes if they could
contain embedded spaces. There is one exception which
you have found out yourself: The "CD" command does not
require quotes (but it does not object to them either).


 
Reply With Quote
 
Danger
Guest
Posts: n/a
 
      1st Feb 2008


"Pegasus (MVP)" wrote:

>
> "Danger" <(E-Mail Removed)> wrote in message
> news:4069A1AB-B395-4E74-B411-(E-Mail Removed)...
> > This batch file is a simple rename of a file folder
> > I can run it on the command line and it works, In a batch file it can not
> > find the file name.
> >
> > the code
> > _____________
> >
> > C:
> > cd C:\Documents and Settings\%USERNAME%\Application Data\Research In
> > Motion\BlackBerry
> > IF Exist intellisync-old (rd /s /q intellisync-old) ELSE (ECHO SUCESS)
> > PAUSE
> > ren intellisync intellisync-old
> > pause
> >
> > ___________________
> >
> > the result
> >
> >
> > C:\Documents and Settings\Administrator\Application Data\Research In
> > Motion\Blac
> > kBerry>IF Exist intellisync-old (rd /s /q intellisync-old ) ELSE (ECHO
> > SUCESS )
> >
> > SUCESS
> >
> > C:\Documents and Settings\Administrator\Application Data\Research In
> > Motion\Blac
> > kBerry>PAUSE
> > Press any key to continue . . .
> >
> > C:\Documents and Settings\Administrator\Application Data\Research In
> > Motion\Blac
> > kBerry>ren intellisync intellisync-old
> > The system cannot find the file specified.
> >
> > C:\Documents and Settings\Administrator\Application Data\Research In
> > Motion\Blac
> > kBerry>pause
> > Press any key to continue . . .
> >
> > _____________________________________
> >
> > the file folder with the correct name is in the correct dir
> >
> > Thank you in advance,

>
> Your batch file tests for the existence of "intellisync.old". It does
> not test for the existence of "intellisync", hence the attempt to
> rename this folder will fail if the folder does not exist. Nothing
> magic there.
>
> About the quotes, missing or otherwise: You ***should***
> always surround file/folder names with quotes if they could
> contain embedded spaces. There is one exception which
> you have found out yourself: The "CD" command does not
> require quotes (but it does not object to them either).
>

In this case "intellisync-old" a folder does exist however it isnt being
deleted at all
hence the sucess message.

section the "intellisync" folder (automajikly created) is assumed correctly
to be there but it cant rename.

>

 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      1st Feb 2008

"Danger" <(E-Mail Removed)> wrote in message
news:AE5C946C-603A-44A2-8B98-(E-Mail Removed)...
>
>
> "Pegasus (MVP)" wrote:
>
>>
>> "Danger" <(E-Mail Removed)> wrote in message
>> news:4069A1AB-B395-4E74-B411-(E-Mail Removed)...
>> > This batch file is a simple rename of a file folder
>> > I can run it on the command line and it works, In a batch file it can
>> > not
>> > find the file name.
>> >
>> > the code
>> > _____________
>> >
>> > C:
>> > cd C:\Documents and Settings\%USERNAME%\Application Data\Research In
>> > Motion\BlackBerry
>> > IF Exist intellisync-old (rd /s /q intellisync-old) ELSE (ECHO SUCESS)
>> > PAUSE
>> > ren intellisync intellisync-old
>> > pause
>> >
>> > ___________________
>> >
>> > the result
>> >
>> >
>> > C:\Documents and Settings\Administrator\Application Data\Research In
>> > Motion\Blac
>> > kBerry>IF Exist intellisync-old (rd /s /q intellisync-old ) ELSE (ECHO
>> > SUCESS )
>> >
>> > SUCESS
>> >
>> > C:\Documents and Settings\Administrator\Application Data\Research In
>> > Motion\Blac
>> > kBerry>PAUSE
>> > Press any key to continue . . .
>> >
>> > C:\Documents and Settings\Administrator\Application Data\Research In
>> > Motion\Blac
>> > kBerry>ren intellisync intellisync-old
>> > The system cannot find the file specified.
>> >
>> > C:\Documents and Settings\Administrator\Application Data\Research In
>> > Motion\Blac
>> > kBerry>pause
>> > Press any key to continue . . .
>> >
>> > _____________________________________
>> >
>> > the file folder with the correct name is in the correct dir
>> >
>> > Thank you in advance,

>>
>> Your batch file tests for the existence of "intellisync.old". It does
>> not test for the existence of "intellisync", hence the attempt to
>> rename this folder will fail if the folder does not exist. Nothing
>> magic there.
>>
>> About the quotes, missing or otherwise: You ***should***
>> always surround file/folder names with quotes if they could
>> contain embedded spaces. There is one exception which
>> you have found out yourself: The "CD" command does not
>> require quotes (but it does not object to them either).
>>

> In this case "intellisync-old" a folder does exist however it isnt being
> deleted at all
> hence the sucess message.
>
> section the "intellisync" folder (automajikly created) is assumed
> correctly
> to be there but it cant rename.
>


Let's do some real tests:
@echo off
cd /d "%UserProfile%\Application Data\Research In Motion\BlackBerry"
IF Exist intellisync-old (rd /s /q intellisync-old) ELSE (ECHO SUCESS)
dir intelli*.*
pause
if exist intellisync ren intellisync intellisync-old
pause

You will find that this batch file works as well as if you executed
the same commands from a Command Prompt.


 
Reply With Quote
 
Danger
Guest
Posts: n/a
 
      5th Feb 2008
Works like a charm wonder why the other did not?
thank you

"Pegasus (MVP)" wrote:

>
> "Danger" <(E-Mail Removed)> wrote in message
> news:AE5C946C-603A-44A2-8B98-(E-Mail Removed)...
> >
> >
> > "Pegasus (MVP)" wrote:
> >
> >>
> >> "Danger" <(E-Mail Removed)> wrote in message
> >> news:4069A1AB-B395-4E74-B411-(E-Mail Removed)...
> >> > This batch file is a simple rename of a file folder
> >> > I can run it on the command line and it works, In a batch file it can
> >> > not
> >> > find the file name.
> >> >
> >> > the code
> >> > _____________
> >> >
> >> > C:
> >> > cd C:\Documents and Settings\%USERNAME%\Application Data\Research In
> >> > Motion\BlackBerry
> >> > IF Exist intellisync-old (rd /s /q intellisync-old) ELSE (ECHO SUCESS)
> >> > PAUSE
> >> > ren intellisync intellisync-old
> >> > pause
> >> >
> >> > ___________________
> >> >
> >> > the result
> >> >
> >> >
> >> > C:\Documents and Settings\Administrator\Application Data\Research In
> >> > Motion\Blac
> >> > kBerry>IF Exist intellisync-old (rd /s /q intellisync-old ) ELSE (ECHO
> >> > SUCESS )
> >> >
> >> > SUCESS
> >> >
> >> > C:\Documents and Settings\Administrator\Application Data\Research In
> >> > Motion\Blac
> >> > kBerry>PAUSE
> >> > Press any key to continue . . .
> >> >
> >> > C:\Documents and Settings\Administrator\Application Data\Research In
> >> > Motion\Blac
> >> > kBerry>ren intellisync intellisync-old
> >> > The system cannot find the file specified.
> >> >
> >> > C:\Documents and Settings\Administrator\Application Data\Research In
> >> > Motion\Blac
> >> > kBerry>pause
> >> > Press any key to continue . . .
> >> >
> >> > _____________________________________
> >> >
> >> > the file folder with the correct name is in the correct dir
> >> >
> >> > Thank you in advance,
> >>
> >> Your batch file tests for the existence of "intellisync.old". It does
> >> not test for the existence of "intellisync", hence the attempt to
> >> rename this folder will fail if the folder does not exist. Nothing
> >> magic there.
> >>
> >> About the quotes, missing or otherwise: You ***should***
> >> always surround file/folder names with quotes if they could
> >> contain embedded spaces. There is one exception which
> >> you have found out yourself: The "CD" command does not
> >> require quotes (but it does not object to them either).
> >>

> > In this case "intellisync-old" a folder does exist however it isnt being
> > deleted at all
> > hence the sucess message.
> >
> > section the "intellisync" folder (automajikly created) is assumed
> > correctly
> > to be there but it cant rename.
> >

>
> Let's do some real tests:
> @echo off
> cd /d "%UserProfile%\Application Data\Research In Motion\BlackBerry"
> IF Exist intellisync-old (rd /s /q intellisync-old) ELSE (ECHO SUCESS)
> dir intelli*.*
> pause
> if exist intellisync ren intellisync intellisync-old
> pause
>
> You will find that this batch file works as well as if you executed
> the same commands from a Command Prompt.
>
>
>

 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      5th Feb 2008

"Danger" <(E-Mail Removed)> wrote in message
news:F14AF84E-5A9A-49D7-81DF-(E-Mail Removed)...
> Works like a charm wonder why the other did not?
> thank you
>


I suspect there was a flaw in your logic.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
printui.dll command line in a batch file with win XP sp2 freddy Windows XP Print / Fax 0 29th Dec 2009 06:05 PM
outlook by command line or batch file. Mary Microsoft Outlook 1 10th Jun 2009 09:25 AM
Command line and batch file customization spacemancw Windows XP Customization 4 26th Apr 2006 02:21 PM
Reboot From Command Line or Batch File Art Sheppard Windows XP General 2 28th Aug 2004 08:05 PM
Strange batch file that doesn't install .exe unattended using /u switch. Doing .exe /u from command line it works Marlon Brown Microsoft Windows 2000 CMD Promt 1 19th Oct 2003 10:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:20 PM.