Solved

Extra character with : Shell "cmd.exe /C copy ...."

Posted on 2006-06-17
6
617 Views
Last Modified: 2012-06-21
Hi There,

I have an ACCESS routine that creates creates a csv file of records that then inserts a header record to the top of the file.

To do this, I create the main csv file ("Main.csv") and then the header file ("Header.csv"), and then use the DOS COPY command to append the 'main' file to the 'header' file.  The command line is:

Shell "cmd.exe /C copy " & strpath & "Header.csv + " & strpath & "Main.csv " & strpath & "OutputFile.csv".

This appears to work fine, however the resulting file ("Output.csv") has the following character (by itself) on the last line : ""

The "" is not the intermediate file "Main.csv" when I look at it before deleting it.

Any ideas?

Cheers,
Mike

0
Comment
Question by:mmorr
  • 3
  • 2
6 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 16928552
another way in DOS is to use TYPE, have u tried that?

type file1 >> file2

puts file1 on the end of file2

other way would be to write your own routine in vba
open both files and write to new file - easily done
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16928582
this bit of code
copies file test.xt and two.txt into a new file called new.txt

Public Sub CopyTwoFiles()

    Dim iFile1 As Integer
    Dim iFile2 As Integer
    Dim iFile3 As Integer
    Dim sLine As String
   
   
    iFile1 = FreeFile
    Open "c:\ee\test.txt" For Input As iFile1
   
    iFile2 = FreeFile
    Open "c:\ee\two.txt" For Input As iFile2
   
    iFile3 = FreeFile
    Open "c:\ee\new.txt" For Output As iFile3
   
   
    'Read File 1 and write to new file
    Do While Not EOF(iFile1)
       Line Input #iFile1, sLine
       Print #iFile3, sLine
    Loop
   
    'Read File 2 and write to new file
    Do While Not EOF(iFile2)
       Line Input #iFile2, sLine
       Print #iFile3, sLine
    Loop
   
    Close (iFile1)
    Close (iFile2)
    Close (iFile3)
End Sub
0
 

Author Comment

by:mmorr
ID: 16928587
Thanks rockiroads.

I tried the following in my vba routine, but it didn't append "Main.csv" to the end of "Header.csv".

Shell "cmd.exe TYPE " & strpath & "Main.csv >> " & strpath & "Header.csv "

Have I go the syntax correct?

Cheers,
M
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
ID: 16928599
dont u need the /C?

e.g.

cmd.exe /c TYPE
0
 
LVL 58

Expert Comment

by:harfang
ID: 16929620
Hello mmorr

I believe that the "" is a lone CR or LF character, while a normal line break would be a CR/LF pair. Have you tried using your file as it is? It might not be a problem at all.

Another idea would be to use the /a switch for COPY to make sure you get an ASCII copy, not a binary copy:

    Shell Environ("comspec") & " /c COPY /a ...."

If that fails, I would go with rockiroads suggestion to use Line Input and Print to recreate all CR/LF pairs afresh.

(°v°)
0
 

Author Comment

by:mmorr
ID: 16930763
Thanks rockiroads.  Adding the "/C" back in fixed the problem - put main.csv on the end of header.csv with no "".
Thanks also harfang for your comment - I tried but still got the "".
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now