another DOS question

DBinPhilly

Registered User.
Local time
Today, 12:52
Joined
May 21, 2013
Messages
42
sorry to persist, but I'm under the gun.

I am trying to copy a pdf file between 2 directories. I am using xCopy, although I'm not married to it.

When I build my copy statement based upon various parameters, it looks something like this:

xCopy C:\PDF995\OUTPUT\*.* P:\Billing\12973\44137.pdf /y

I might note that there is only one file in C:\PDF995\OUTPUT at a time. So I copy what is there, delete it and it is empty until the next usage.

The problem is: when it executes the statement, I get a DOS message asking whether what is being copied is a File or a Directory.

How can I identify that without needing to respond to a message?
 
What about using file system object. Also, since you mention that after you copy the file you delete it, you could use MoveFile instead of CopyFile and that would save you a step. I show both ways, but you would only need one or the other. I'm using variables, but you could also hard code. Also, I haven't tested with wild cards (*).

Code:
    Dim fso As New FileSystemObject
    Dim stFileName As String
    Dim stSourcePath As String
    Dim stDestPath As String

   stFileName = '[I][B]44137.pdf'
   [/B][/I]stSourcePath = '[I][B]C:\PDF995\OUTPUT\'[/B][/I]
   stDestPath = '[I][B]P:\Billing\12973\[/B][/I]'

' Copy the file
   fso.CopyFile stSourcePath & stFileName, stDestPath & stFileName

'Move the file
   fso.MoveFile stSourcePath & stFileName, stDestPath & stFileName
 
I tried this approach. I had to identify a DLL to use, so I chose:
C:\Windows\SysWOW64\sccrun.dll

It compiles but when executed it gives me an
"Path Not Found" message
The statement I am using in my VBA is:

fso.MoveFile C:\PDF995\OUTPUT\*.* P:\Billing\12973\44141.pdf

Both paths do exist. Any ideas?
note: the second path is put together using variables. What you see is the end result of the compilation of a Job number (subdirectory) and invoice number (file name)
 
Perhaps the wildcard is causing the problem. Think of it this way, consider if there was more than one file, the program would be trying to move all the files into the same file name, probably not what you are after. Since you indicated that you only have one file at a time in that folder, anychance you could specify the name or rename the source file upfront, and then do the move. Otherwise, you may need to look for some vba that could read the directory and extract the filename for you then that could be passed as the sourcefile variable.
 
You have specified multiple files and xcopy won't copy multiple files to a single filename.

If the destination doesn't exist then you would need to include the /I switch to indicate your desination is a directory.
http://www.computerhope.com/xcopyhlp.htm

xcopy C:\PDF995\OUTPUT\*.* P:\Billing\12973 /I /Y
 
I'm afraid it was much easier to do than all the concepts passed to me. I thank you for your help.

the FileCopy statement did the trick.

FileCopy stSourcePath, stDestinationPath

I threw in a routine to make sure the destination subdirectory was created before the FileCopy, and then executed a kill statement on the stSourcePath after the FileCopy was completed.
I've successfully tested it in three different programs.

Thank you for the help and suggestions.
 

Users who are viewing this thread

Back
Top Bottom