[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Shell String

Posted on 2002-04-07
9
Medium Priority
?
304 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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 200 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

656 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