-1

I am new to xcopy. I am trying to move a file that is in excel format to a new destination and as a csv file. I have to do this so that the DMExpress ETL job can move the file and then read it. This is how my company wants it done.

So this is what I have so far:

xcopy "\blah\blah\blah\blah*.xlsx" "\blah\blah\blah\blah\Badge.csv" /Y <f.txt> create_copy_script.log

Not sure why I have to have the <f.txt>, if someone could explain that, that would be great. But that is a secondary question.

When I run this in a .bat file, and then open the file (which does move and does change its name), I get the following error:


The file format and extension of "Badge.csv" don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway?

Now, the next part of the ETL has to open this file and load the data into a database table.

To be able to do this right now, I have to open this file, resave it as a csv file and then the second part of the ETL works perfectly. But I want automation. I cant open this file on the weekends, that is dumb.

So, I am assuming I am doing something wrong with my script. Should the move and rename be separate? is there a better way? Maybe I can't just rename the file and extension, if I cannot what is the better way to do that?

Note: I need to keep the original file in its original folder and make a copy of it instead and move that, which is why I am using xcopy.

2
  • 1
    I see no mention of your error in the xcopy docs, but it suggests to me that it's warning you that you're trying to change a file's extension. Try not doing that (copying to a new .xlsx file) and see whether you get the error. If that is the cause of the error, and you deliberately want to change the extension, there is no cause for concern, you can safely ignore the error. Windows always gets very alarmed when someone changes a file extension. Commented Jan 23 at 21:30
  • well when my program tries to open this (DMX) it says there is an error. Because it is not able to read the file. Which tells me that although this is a warning for a human to open the file, the program does not know this and is not able to open it. So, I am looking for a solution that can convert the excel file to a csv file without getting this warning.
    – Sevanna
    Commented Jan 24 at 17:58

1 Answer 1

1

Microsoft Excel .xlsx files are a very different format from comma separated value .csv files. Your xcopy command changes the name of the file, but not the contents.

One of the simpler ways to automate this could be with powershell, using the ImportExcel module:

# only need to install once on a system
Install-Module ImportExcel

# then automate this line to copy and convert your file to a .csv
Import-Excel 'c:\path\to\input.xlsx' | Export-Csv 'c:\path\to\output.csv' -NoTypeInformation

And there are similar python modules if you prefer that. It's not something you can accomplish in basic CMD shell without extra tools

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .