Solved

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

Posted on 2006-06-17
6
618 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

813 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

11 Experts available now in Live!

Get 1:1 Help Now