Copy and rename file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rajgan
Posts: 3
Joined: 05 Jun 2016 02:52

Copy and rename file

#1 Post by rajgan » 05 Jun 2016 03:14

Need script for the below.

Files names Day 1.Jpg … Day 60.jpg are available in one directory on the server. Need to copy daily bases from Day 1.jpg to Day 60.jpg to rename file File Tips.jpg in the path \\server path\ File Tips.jpg

Thanks you

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy and rename file

#2 Post by foxidrive » 07 Jun 2016 16:39

rajgan wrote:Need script for the below.

Files names Day 1.Jpg … Day 60.jpg are available in one directory on the server.

I'm with you up to this part.
Need to copy daily bases from Day 1.jpg to Day 60.jpg to rename file File Tips.jpg in the path \\server path\ File Tips.jpg

I'm not sure what you are asking for in this part.

rajgan
Posts: 3
Joined: 05 Jun 2016 02:52

Re: Copy and rename file

#3 Post by rajgan » 23 Jun 2016 13:10

Thanks you for replay.

The file names start from "desktop 01.jpg" to "desktop 60.jpg" are stored in the server1 share folder (\\server1\desktop 01.jpg).

In another server2, "desktop image.jpg" file are stored in share folder (\\server2\desktop image.jpg). This file is used for desktop background image (wallpaper).

An daily bases, the files are start from "desktop 01.jpg" to "desktop 60.jpg" copy from server1 and rename to "desktop image.jpg" and save to \\server2\desktop image.jpg

The task is windows wallpaper image is changed daily on server2.

For example:
Day 1 - desktop 01.jpg
Day 2 - desktop 02.jpg
.
.
Day60 - desktop 60.jpg
Day61 - desktop 01.jpg

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy and rename file

#4 Post by foxidrive » 23 Jun 2016 13:55

rajgan wrote:The task is windows wallpaper image is changed daily on server2.

For example:
Day 1 - desktop 01.jpg
Day 2 - desktop 02.jpg
.
.
Day60 - desktop 60.jpg
Day61 - desktop 01.jpg


I see, that's clearer, thank you.

Are there only 60 files?
Would a random picture from the 60 jpg files be more useful, or do you want to cycle in 60 day sections?

rajgan
Posts: 3
Joined: 05 Jun 2016 02:52

Re: Copy and rename file

#5 Post by rajgan » 02 Jul 2016 05:57

Thanks you for replay.

Yes, I have only 60 files.

Yes, I need 60 cycle.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Copy and rename file

#6 Post by foxidrive » 03 Jul 2016 06:31

This will copy the new picture number every time it is launched, and in a 60 number cycle.
When it reaches 60 it will begin at 01 again.

To test it just keep launching it. It will not copy any picture and only show the command on the screen.
Once you are happy with it then remove the last line with pause in it and also the echo at the very start of the line before the word copy.

Code: Select all

@echo off
if not exist "%temp%\picnum.bin" >"%temp%\picnum.bin" echo.100
find "160" < "%temp%\picnum.bin" >nul && >"%temp%\picnum.bin" echo.100
for /f "usebackq delims=" %%a in ("%temp%\picnum.bin") do set /a "num=%%a+1"
set "picnum=%num:~-2%"
echo copy /b "\\server1\desktop %picnum%.jpg" "\\server2\desktop image.jpg"
>>"%temp%\picnum.bin" echo.%num%
pause & goto :EOF

Post Reply