Solved

Shell String

Posted on 2002-04-07
9
300 Views
Last Modified: 2012-06-22
I am attempting to poll through a number of network mappings and perform copy and rename command line executions from within a Shell statement.  I can't seem to get the syntax correct.  Keep getting a Cannot fine the file error.

Dim vShellString as string
Dim x as variant

vShellString = "Rename c:\access\filename.mdb filename-final.mdb"
x = Shell(vShellString)

If I execute the exact characters in a MSDOS i.e. Rename . . . .mdb  as stated above it works fine.  But, by putting it into a string there must be a syntax problem with quotes, etc. that it does not recognize the path that is being described.  I have tried cancatenating chr(34) on both ends of the string, around the actual path only, chr(39) around the path only, etc.

Can't seem to get it to work.  

Ideas experts.

Bob Scriver
0
Comment
Question by:Bob Scriver
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 6

Expert Comment

by:xSinbad
ID: 6924236
Try ading the full path to rename.exe
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6924239
xSinBad:
I don't understand what you mean by your comment.  Please elaborate.

Bob Scriver
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6924278
I have resolved this question myself.  The shell statement requires a reference to the command file ( i.e. cmd /c ) within the shell string.

It should look like this:

vShellString = "cmd /c Rename c:\access\filename.mdb filename-final.mdb"

The shell statement must reference the command file to know what to do with the Reserved Command word Rename, Copy, etc.  

I will ask CS to reduce the points to 0 but I will leave this question active for others to benefit from this finding.

Bob Scriver
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:ornicar
ID: 6924333
Just note that you can rename a file without invoking the DOS command. Simply:

Name [SourceFile], [DestFile]

Will do the job fine with no splashing DOS window.

You can even trap the error:

On Error Resume Next

Name [SourceFile], [DestFile]
if err <> 0 then
    msgbox "Error on renaming file: ", Error$
endif
On Error Goto 0
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6924375
Ornicar:

Please be more specific because I can only find Name as a property and not in the command type format that you suggest.

Bob
0
 
LVL 9

Accepted Solution

by:
ornicar earned 50 total points
ID: 6924378
Name is also a file command, The exact command is:

NAME "c:\access\filename.mdb" AS "c:\access\filename-final.mdb"

I forgott the AS. My fault.
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6924468
Ornicar:
Thanks for the follow-up to this question.  Although the original question had to do with the format of the Shell string you have given me a better way of manipulating the files with the Name command.  Also, the FileCopy and Kill commands give me everything that I need.  so I am going to award you the points for this question and with draw my request to CS to reduce the points to 0.  

Bob Scriver
0
 
LVL 3

Author Comment

by:Bob Scriver
ID: 6924469
Your comment is exactly what was needed to finish off my application.  Thanks

Bob scriver
0
 
LVL 9

Expert Comment

by:ornicar
ID: 6924822
You are welcome
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question