newtoperlpgm
asked on
Windows copy two files into one file and rename file
On my windows server I have two files, File1.csv and File2.csv. I need to concatenate the two files, or append File2.csv to File1.csv, into a third file, File3.csv; either way, as long as the contents of File1.csv is first in the File3_CURRENTDATE.csv
I will need to have this run via a .bat file that will perform the task once a week. I also need to know how to name the resultant file with the currentdate appended to the name before the .csv suffix. For example
File1.csv File2.csv >> File3_20140102.csv
Thanks so much for any help you can provide.
I will need to have this run via a .bat file that will perform the task once a week. I also need to know how to name the resultant file with the currentdate appended to the name before the .csv suffix. For example
File1.csv File2.csv >> File3_20140102.csv
Thanks so much for any help you can provide.
ASKER
Thank you but I need to automate the process to add the current date to the filename File3.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In powershell you can run this:
start -> run -> powershell
then type the following and save the file as "combine.ps1"
------------------------
Set-ExecutionPolicy unrestricted
$combinedfile="c:\resultfi le_" + (get-date).toshortdatestri ng() + ".csv"
add-content -value (get-content c:\csvfile1.csv) -path $combinedfile.csv
add-content -value (get-content c:\csvfile2.csv) -path $combinedfile.csv
-------------------------
Run the combine.ps1 file as scheduled task if you want to automatically run on schedule.
Input files are c:\csvfile1.csv and c:\csvfile2.csv
Output file: c:\resultfile_02/01/2014.c sv
( The date is added based on the day you execute the .ps1 file)
You can refer the following to schedule the above as task in task scheduler.
http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/11/weekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script.aspx
start -> run -> powershell
then type the following and save the file as "combine.ps1"
------------------------
Set-ExecutionPolicy unrestricted
$combinedfile="c:\resultfi
add-content -value (get-content c:\csvfile1.csv) -path $combinedfile.csv
add-content -value (get-content c:\csvfile2.csv) -path $combinedfile.csv
-------------------------
Run the combine.ps1 file as scheduled task if you want to automatically run on schedule.
Input files are c:\csvfile1.csv and c:\csvfile2.csv
Output file: c:\resultfile_02/01/2014.c
( The date is added based on the day you execute the .ps1 file)
You can refer the following to schedule the above as task in task scheduler.
http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/11/weekend-scripter-use-the-windows-task-scheduler-to-run-a-windows-powershell-script.aspx
ASKER
@Jeremy Weisinger I tested your solution and it worked for me, so in order to run it I will need to add directories in order for it to know where my files that I want to be copied are correct? Thanks.
ASKER
***update, never mind, I figured that out by changing the format in the (set fileDate=%%d%%b%%c)
Jeremy Weisinger, I also have a question about the date,
if I want to have 20140102 as todays date, how can I change it so that it appears that way. My date appeared 20140201.
Thank you.
Jeremy Weisinger, I also have a question about the date,
if I want to have 20140102 as todays date, how can I change it so that it appears that way. My date appeared 20140201.
Thank you.
change it to fileDate=%%d%%b%%c
@newtoperlpgm "Jeremy Weisinger, I also have a question about the date,
if I want to have 20140102 as todays date, how can I change it so that it appears that way. My date appeared 20140201."
Yes, I usually put the month first so that it's easy to sort by date just by sorting the filename. But it looks like you already figured out how to change the order.
Cheers!
JW
if I want to have 20140102 as todays date, how can I change it so that it appears that way. My date appeared 20140201."
Yes, I usually put the month first so that it's easy to sort by date just by sorting the filename. But it looks like you already figured out how to change the order.
Cheers!
JW
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for newtoperlpgm's comment #a39752713
for the following reason:
solution provided.
Accepted answer: 0 points for newtoperlpgm's comment #a39752713
for the following reason:
solution provided.
I believe newtoperlpgm mistakenly choose their own answer as the solution when they stated my answer was correct.
ASKER
oops that is correct Jeremy I inadvertently clicked on the wrong comment to Accept as Solution. Thanks for noticing. I will correct.
No problem. Thanks!
Open in new window
If your files are binary, then use this:Open in new window