You are not logged in.
Pages: 1
Hi experts,
I have a funny scenario,
i have folder with multiple files.
I want to move all the files that has 1234 in the filename to a new folder and rename the newest file to 1234.txt
Example:
I have this three files in a folder, i wish to copy all of them to another folder and rename the newest file to 1234.txt
1. abc-1234-abc.txt /created at 2015
2. def-1234-def.txt /created at 2013
3. ghi-1234-ghi.txt /created at 2011
I have tried this command but it dose not rename the newest file:
move *1234*.* C:\Users\guyo | dir /o-d c:\users\guyo | ren c:\users\guyo\*1234*.* 1234.txt
Please help!
Does it even possible with CMD?
Offline
@echo off
setlocal
for /F "delims=" %%a in ('dir /O:D /B *1234*.*') do (
move "%%a" C:\Users\guyo
set "newest=%%a"
)
ren "c:\users\guyo\%newest%" 1234.txt
Most commands accept data as parameters; a few ones read data from the keyboard, like the label of the disk in FORMAT command.
You are mistaken a parameter for data read from keyboard: REN command does not read data from keyboard, so the file name must be given as parameter.
Last edited by Aacini (13 Jun 2016 13:42)
Offline
Pages: 1