Can you help me write a batch file that will move a csv file and rename it?

I need to move & rename this file:

C:\Test\Data_04_07_16.csv

to here:

C:\Test\New_Data_42467.csv

Please note the name of the file will change every day based on the date (e.g. ‘04_07_16’ = 4/7/16). Please also note, I need the file moved and renamed so that the date remains in the file name, but is formatted in such that excel can resolve it (e.g. ‘42467’ = 4/7/16 in Excel).

THANK YOU!!!

6 Spice ups

I can’t figure out why you need the “Excel” date in the file name. Excel does nothing with the file name itself. It also looks like in your info that only a rename is needed because the folder name stays the same.

The csv files do not have time stamps, except for in the file name. Once I merge the files I’ll be able to associate the data rows with a file name. If I format the file name correctly, I’ll easily be able to convert file names to dates in Excel.

For example, after merging all the csv files I’ll have a data row along with a column (Called File Name). If the file name = 42467.csv, then I can remove the “.csv” and reformat the column as to become a Date instead of a File Name. 42467 becomes 4/7/16 in excel.

Thanks.

I’m generally confused about file names being inside the combined csv? Anyway, this code should give you some pieces to the puzzle:

$filename = 'Date_04_07_16.csv'
$date = [datetime]::ParseExact($filename,"'Date_'MM_dd_yy'.csv'",[cultureinfo]::InvariantCulture)
[Math]::Floor($date.ToOADate())

Since you already have to truncate the “.csv”, which can be done through a ‘find and replace’. Why can’t you use the original file name “04_07_16.csv”, truncate the “.csv”, then replace “_” with “/” which excel will automatically identify as a date?

You will save steps and the math needed to convert the date to a number in the batch file. You can even create a macro to save more steps.

powershell’s deffinitely the way to go for this .

How do you create that file and give it the name with the date in it??

Where does that bit come from

$date=get-date -UFormat "%d_%m_%y"
$filename="data_"+$date+".csv"
$path="c:\test"
$old=join-path -path $path -child-path $filename
$new= $path + "new_"+ $filename
rename-item -path $old -newname $new

Something like this would be a possible way out.

Please provide a sanitized sample of the csv file so we can see how it looks and throw something together that would be what you look for . Off course it won’t improve your knowledge when we do the homework but it can be a beginning for you to learn it yourself.