Computer Hope

Microsoft => Microsoft DOS => Topic started by: chachie on June 10, 2019, 10:04:49 AM

Title: Copying a file from a folder with today's date to another folder.
Post by: chachie on June 10, 2019, 10:04:49 AM
Hello everyone,

I'm hoping someone can help as I'm not the best a creating batch files.

I would like to copy a csv file from a folder and save it in another folder. The source folder is named with today's date (i.e. 06102019) and the destination folder does not change. The CSV will have to overwrite the previous file.

For example:
The batch file will run and look for the folder with today's date
Copy hg200T.csv from C:\monitoring\06102019
Paste (and overwrite existing file) to C:\warning\excel\stream

Thanks in advance
Title: Re: Copying a file from a folder with today's date to another folder.
Post by: DaveLembke on June 10, 2019, 02:38:28 PM
Looking at what you have, the folder which is by name dated needs to be removed daily to remove today yesterdays folder and data?

I have an easy solution for this but I want to confirm some information before sharing the batch script with you as for I don't want to destroy data on you that may be at the destination that goes through a daily purge in prep for new data.

*** Is there any data that needs to remain at C:\warning\excel\stream or can this folder named Stream and all data in the root of Stream and its subfolders be wiped clean of all data and repopulated with the latest data?

Basically the batch I have in mind uses a RD Foldername /S/Q which will remove Stream and all data files and folders and subfolders and then create a new folder named Stream, and then copy the latest CSV file to C:\warning\excel\stream

But holding off on sharing it in this response because it can be bad if you plan on any other data remaining at Stream.  ;D
Title: Re: Copying a file from a folder with today's date to another folder.
Post by: chachie on June 11, 2019, 06:42:47 AM

*** Is there any data that needs to remain at C:\warning\excel\stream or can this folder named Stream and all data in the root of Stream and its subfolders be wiped clean of all data and repopulated with the latest data?



Thanks for the reply. To answer your question, no I will not be needing any info the the stream folder. The stream folder was created to save the daily csv file. I have an excel lookup which checks the daily csv for anomalies. If nothing is found, nothing happens and we move on to the next day. If an anomaly is found, an email is sent and we investigate. That's it.

Thanks again
Title: Re: Copying a file from a folder with today's date to another folder.
Post by: DaveLembke on June 11, 2019, 03:55:17 PM
Unable to test this at my workplace but this should do the trick. I typed this all up off top of my head without testing. Also to note, I have the batch stepping its way to the destination Stream that is to be destroyed and recreated vs a direct target path. A direct target path could be used but this should do the trick. :)

XCOPY was used because your dated folder at c:\monitoring with a positive match to hg200T.csv will create the date-named-folder and copy the file over to this C:\warning\excel\stream location.

Code: [Select]
c:
cd\.
cd warning
cd excel
rd stream /s/q
md stream
xcopy c:\monitoring\hg200T.csv c:\warning\excel\stream /s/y
Title: Re: Copying a file from a folder with today's date to another folder.
Post by: DaveLembke on June 12, 2019, 01:20:22 AM
Just got home from work and tested this on my home computer and forgot to add wildcard * which corrects for the ever changing folder name that is date named.

Here is it corrected and cleaned up:
Code: [Select]
rd c:\warning\excel\stream\ /s/q
md c:\warning\excel\stream
xcopy c:\monitoring\*hg200T.csv c:\warning\excel\stream /s/y