- Local time
- 1:44 PM
- Posts
- 223
- OS
- Windows 11 Home 64-bit
Good morning all,
It has been over 35 years ago that I was working on BAT files, so I forgot more than I ever knew about those.
I am trying to copy all XLSB files (with different file names that might change day by day) from directory TEST to directory ONEDRIVE
But when the destination file already exists I want to add a number to the filename.
My intention is to run this file on every re-boot.
As an example I used the file FruitList.xlsb and the desired result in the ONEDRIVE directory should be:
First time copying: FruitList.xlsb
Second time copying: FruitList(1).xlsb
Second time copying: FruitList(2).xlsb
et cetera
This is the BAT code I used:
Below the result:
As one can see it basically works ok . . . BUT the extention part is not as desired.
All help will be appreciated
Thanks
It has been over 35 years ago that I was working on BAT files, so I forgot more than I ever knew about those.
I am trying to copy all XLSB files (with different file names that might change day by day) from directory TEST to directory ONEDRIVE
But when the destination file already exists I want to add a number to the filename.
My intention is to run this file on every re-boot.
As an example I used the file FruitList.xlsb and the desired result in the ONEDRIVE directory should be:
First time copying: FruitList.xlsb
Second time copying: FruitList(1).xlsb
Second time copying: FruitList(2).xlsb
et cetera
This is the BAT code I used:
Batch:
@echo off
set Source=D:\Test\*.xlsb
set Destination=D:\OneDrive\
set Filename=*.xlsb
set a=1
:loop
if exist %Destination%\%Filename%(%a%).xlsb set /a a+=1 && goto :loop
copy %Source% %Destination%\%Filename%(%a%).xlsb
@echo on
DIR /B D:\OneDrive\*.xlsb
PAUSE
Below the result:
D:\Test\FruitList.xlsb
1 file(s) copied.
D:\Desktop>DIR /B D:\OneDrive\*.xlsb
FruitList.xlsb
FruitList.xlsb(1).xlsb
FruitList.xlsb(2).xlsb
D:\Desktop>PAUSE
Press any key to continue . . .
As one can see it basically works ok . . . BUT the extention part is not as desired.
All help will be appreciated
Thanks
Last edited:
My Computer
System One
-
- OS
- Windows 11 Home 64-bit
- Computer type
- Laptop
- Manufacturer/Model
- MSI Laptop - Commercial 14 H A13MG vPRO-098
- CPU
- Intel Core i7 13700H
- Motherboard
- MSl Co., Ltd. MS-14L1 (U3E1)
- Memory
- 32GB DDR4
- Graphics Card(s)
- Intel Iris Xe Graphics
- Sound Card
- Intel Smart Sound Technology - Realtek High Definition Audio
- Monitor(s) Displays
- Generic 1920x1200 @ 60Hz
- Screen Resolution
- 1920 x 1200 pixels
- Hard Drives
- 1TB NVMe WD SSD
- Mouse
- Bluetooth
- Browser
- Microsoft Edge
- Antivirus
- McAfee , Malwarebytes





