Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have a directory set up that stores *.CSV files.
I need to read the file name of the file, create a directory with the same file name, move the *.csv file into the new directory and rename the file to the date and time.CSV

rename the file to the date and time.CSV
Do you want the current date/time or the file creation date/time?

Hi,
Yes I do. I have found this that nearly fits the bill
for /f %%F in ('dir/b/a-d *.csv') do call :sub1 %%F
goto :eof:sub1
set name=%1
md %name:~0,6%
move %* %name:~0,6%but only looks for a specific string length of file name rather than *.CSV.
Can you help please?

You didn't answer my query on date/time so I've used the file created date and time.
Without knowing your date/time format the script is set up for my format which is dd-mm-yyyy hh:mm. You will have to change
set file=!file:~6,4!!file:~3,2!!file:~0,2!_!file:~11,2!!file:~-2!.csvto suit your format if it is different. The output files are named in the format yyyymmdd_hhmm. Once you have finished testing change the "Copy" command to "Move". The script is untested.@echo off cls setlocal enabledelayedexpansion for /f "delims=" %%A in ('dir /a-d /b /tc "*.csv"') do ( md "%%~nA" set file=%%~tA set file=!file:~6,4!!file:~3,2!!file:~0,2!_!file:~11,2!!file:~-2!.csv copy "%%A" "%%~nA\!file!"> nul )Good luck

Sorry about not answering your question properly.
Your script works as indicated but I have changed the final date and time format of the CSV file.
Many thanks for your time to answer my question.

![]() |
find and replace string i...
|
Find a line number then c...
|
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |