I have a file book.csv in folder C:\sam
. I want to write .bat script renaming it first and then moving to C:\samy
. Also the book.csv will be dynamic file name.
I want a script so my file move from one folder to another and creates a new file, if any file already exists.
For example, I have a file test.csv in Downloads folder. When I run the below script if overrides the file if any file exists with the same name in downloads1 folder.
But I want, it shouldn't override the existing file but both the files should be there; maybe it changes the name.adds 1,2 behind.
move C:\user\Downloads\*.csv C:\user\downloads1\
Also I know using /-Y will ask me I needs to override. But I want to do this automatically.
move /-Y C:\user\Downloads\*.csv C:\user\downloads1\
@echo off
set /p new_name=set a new name
move /Y C:\sam\books.csv C:\samy\%new_name%.csv
or
@echo off
move /Y C:\sam\books.csv C:\samy\%%~1.csv
The first will ask the user for the new name.The second relies on command line argument e.g. movescript.bat new_name
EDIT
After the second request in the comments bellow it appears that the ren
command should be used after all:
@echo off
set /p new_name=set a new name
move /Y C:\sam\books*.csv C:\samy\
cd /D C:\samy\
ren book_????_??_??.csv %new_name%_????_??_??.csv
or
@echo off
move /Y C:\sam\books*.csv C:\samy\
cd /D C:\samy\
ren book_????_??_??.csv %%~1_????_??_??.csv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With