?
Solved

File not found with Shell Command

Posted on 2006-03-28
10
Medium Priority
?
398 Views
Last Modified: 2008-02-01
This is the code

xyz = "ren  """ & sPath & "\*.csv"" """ & sPath & "\*.old"""
myval = Shell(xyz)

Gettign file not found. When I run it from DOS, it works fine
Whats wrong ?

0
Comment
Question by:jitganguly
  • 5
  • 4
10 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 16313123
xyz = "ren  """ & sPath & "\*.csv"" """ & sPath & "\*.old"""
debug.print xyz   '<--- What does this display in your Immediate Window?
0
 
LVL 20

Author Comment

by:jitganguly
ID: 16313142
Ren "\\rabofspr\global\funds xfer\Chase\*.csv" "\\rabofspr\global\funds xfer\Chase\*.old"
0
 
LVL 8

Expert Comment

by:Leo Eikelman
ID: 16313450
instead of the Shell function use ShellWait

Here is a code Example

------------------------------------------------------------------------------------------


Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long

Private Function ShellWait(PathName, Optional WindowStyle As VbAppWinStyle = vbHide) As Double
Dim H As Long, R As Long
    H = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(PathName, WindowStyle))
    Do
        GetExitCodeProcess H, R
        DoEvents: Sleep 100
    Loop While R = STILL_ACTIVE
End Function

Private Sub Form_Load()
Dim q As String
q = "dsquery user -name > c:\query.txt"
ShellWait "cmd /c " & q, vbHide

'open file for input etc...here
End Sub

---------------------------------------------------------------------------------


Cheers,

Leo
0
Technology Partners: 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 8

Expert Comment

by:Leo Eikelman
ID: 16313460
above replace

q = "dsquery user -name > c:\query.txt"

with your cmd you are executing

q = "ren  """ & sPath & "\*.csv"" """ & sPath & "\*.old"""

Cheers,

Leo
0
 
LVL 20

Author Comment

by:jitganguly
ID: 16313462
Boy,
Can I have a simple code that would rename two files. I would prefer using wildcards. Both are .csv extension
0
 
LVL 8

Expert Comment

by:Leo Eikelman
ID: 16313475
you can use wildcards.

Look at my above comment.

This code isn't that complicated

Leo
0
 
LVL 20

Author Comment

by:jitganguly
ID: 16313481
Why can't I use
1. Shell
2. FSO
0
 
LVL 8

Accepted Solution

by:
Leo Eikelman earned 2000 total points
ID: 16313557
What about instead of this

xyz = "ren  """ & sPath & "\*.csv"" """ & sPath & "\*.old"""
myval = Shell(xyz)

try this

myval = Shell "cmd /c ren  """ & sPath & "\*.csv"" """ & sPath & "\*.old"""

cheers,

Leo
0
 
LVL 20

Author Comment

by:jitganguly
ID: 16313612
You are the man

Of course I had to do little modification, as the 2nd parameter in ren does not require full path

xyz = "cmd /c ren  """ & sPath & "\*.csv"" *.old"

I always give 'A' (since I am expert too :-)
0
 
LVL 8

Expert Comment

by:Leo Eikelman
ID: 16313714
yeah I overlooked changing the parameters.  

Glad it's working

Cheers,

Leo
0

Featured Post

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!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 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