Batch File Copy and Rename - windows

Currently looking to copy and rename a file from a C:Drive source to a G:Drive destination by using a batch file. Currently have the following code:
robocopy C:\Users\abronk04\Desktop\Test G:\Users\abronk04\Desktop\Backup /e /purge
ren G:\Users\abronk04\Desktop\Backup accessbackup.jpg backup.jpg
The file will successfully copy, but there is no rename. Do I need to specify a file I am looking to rename? My batch file will copy an entire folder to another destination, unsure if that is the problem here...

I think you ren syntax is not correct.
Maybe try the following after copying the directory
pushd G:\Users\abronk04\Desktop\Backup
ren accessbackup.jpg backup.jpg
popd
This way you will temporarily change your working directory to the sink-path and then change it back

Related

How to batch copy files based on a list (txt) in to another folder with same directory structure?

I have a root directory with over 25,000 files in it. These files are in loads of different subdirectories.
I also have a text file with 4300 lines in it, each line is an absolute path to one of the files in the directory. Like below,
c:\dir1\hat1.gif
c:\dir1\hat2.gif
c:\dir1\dir2\hat1.gif
c:\dir1\dir2\hat2.gif
c:\dir1\dir3\cat.zip
c:\dir1\dir3\banana.exe
I also have another root directory witch is a copy of the original root directory structure but all the directories are empty.
I would like to copy all the files listed in the text file to the directory which is empty and place all the copied files inn the respected subdirectories.
if I use the following batchfile I keep getting file overwrite prompts because it is not copying the files to the correct directories.
#echo off
set dst_folder=c:\DSTN2
for /f "tokens=*" %%i in (USEDFILES.txt) DO (
xcopy /S/E "%%i" "%dst_folder%"
)
How do I modify this so the files are copied to the correct directory?
Since you are copying specific files from a list, you need to make sure the directory structure exists in the destination if you want it in a similar folder structure. So using the power of the FOR command modifiers you can get the file path only from the file name in the file list. You will use that modifier to create the destination directory and also use it as the destination for the XCOPY command.
I have taken the liberty of providing best practices for all the code you are using.
#echo off
set "dst_folder=c:\DSTN2"
for /f "usebackq delims=" %%G in ("USEDFILES.txt") DO (
mkdir "%dst_folder%%%~pG" 2>NUL
xcopy "%%~G" "%dst_folder%%%~pG"
)

Copy Directory files to another directory in batch file without asking?

I have created a batch file to copy one folders files to another folder.
This code XCOPY C:\Temp\a.txt C:\Temp2\a.txt /Q works but when i run this file it ask Overwrite C:\Temp2\a.txt (Yes/No/All)?
I want to do this without asking this question. How can i do ? And i want to this for aspx or aspx.cs files
From the manual:
/Y Suppresses prompting to confirm you want to overwrite an existing
destination file
So just add the /Y option in order to overwrite all files without asking.
If you want to copy all files that contain "aspx", you can use
XCOPY C:\Temp\aspx* C:\Temp2\ /Q /Y
You can try this :
XCOPY C:\Temp\a.txt C:\Temp2\a.txt /Q /Y

how to copy directory of specific files in batch file

c:/--> folder1-->
folder2->
img001.png
img002.jpg
img003.png
I having kind of folder structure.
I need to copy a single file from this folder to Destination folder.
source : "c:\folder1\folder2\imgoo1.png"
Destination:"D:\folder1\folder2\imgoo1.png"
need output:
D:/--> folder1-->
folder2->
img001.png
Note:I need batch file format
robocopy "c:\folder1\folder2" "d:\folder1\folder2" "img0001.jpg"
Since robocopy is not included in windows XP, this can be done with plain xcopy
xcopy "c:\folder1\folder2\img0001.jpg" "d:\folder1\folder2\"
for %%f in (img001.png img002.jpg img003.png) do copy /b "c:\folder1\folder2\%%f" "d:\folder1\folder2\"
Note that thw directory separator in windows is \, not /. / is used as a command-switch - /b in the above case means "copy in binary mode'.
Note that you do not say whether the batch should check whether the destination directory exists or whether the destination filename already exists.
md "d:\folder1\folder2" 2>nul
will force the destination filename to exist (2>nul suppresses the 'already exists ' message)
You can add an extra switch /y to the copy command to force overwrite in the case that the destination file already exists.
You can add >nul to the copy command to suppress the 1 file copied message.
This will copy that one file. The target filename is not required but can be left in.
copy "c:\folder1\folder2\imgoo1.png" "D:\folder1\folder2\imgoo1.png"
This assumes that the folders already exist.

How can I do a batch file to copy and rename a file?

I am trying to create a batch file to copy a "folder" as a backup to a new destination. However, I need to add a date stamp of the file name.
for example folder is myFolder when I copy it I want to to be named myFolder_todays_date
I want to be able to copy the folder and it's content.
I found the xCopy but I am not sure how to write it correctly.
now I tried xCopy /e/i dir newDir
How can I append the date to the folder name?
I appreciated your help on how to write this batch file correctly.
Thanks
#echo off
mkdir %1%DATE%
xcopy /s %1 %1%DATE%
This accepts the name of the folder as a command line argument.
For example if the above batch file is called bkup.bat and you want to make a backup of a directory called work, you run it as
bkup.bat work
It copies it into the current directory. You can accept a 2nd command line argument (%2) & also use that if you want to copy to a different directory
xcopy /s %1 %2\%1%DATE%

Batch script to rename and move files

I have a radio management system which is capable of running batch scripts after shows.
I'm looking for a batch script file that renames any file in the directory like so:
1.mp3 --> [Replay]1.mp3
And then move the file from folder a to folder b.
Any thoughts on how do i go about creating such script in a syntax level?
Here you go
ren *.mp3 [Replay]*.*
There are many ways to do what you request, this script does that by searching all mp3 files in the current folder and move them to folderb specifying a new name.
#ECHO off
FOR %%i IN (*.mp3) DO (
MOVE "%%i" "folderb\[Replay]%%i"
)

Resources