I noticed something strange when executing the Copy command from a Windows batch file and was wondering if anyone has encountered this before and can explain the cause.
I have a line in a batch file which copies an Excel file from location A to location B and also renames the file. For example:
Copy \\server\share\folder\locationA\file_*.xlsx \\server\share\folder\locationB\file.xlsx /y
The copy looks like it completes fine, since the Excel file is present in location B, however when I go to open the file, I get an error message stating that:
"Excel cannot open the file... because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."
I ran some tests with the above command line and noticed that this issue only happens if I use a wildcard in the filename in part A. For example, the file copies and I can open it just fine with this command:
Copy \\server\share\folder\locationA\file_LongName.xlsx \\server\share\folder\locationB\file.xlsx /y
I realize that there are numerous ways to fix this, but I'm not interested in a solution, I'm interested in an explanation. My question is why is this happening?