- Local time
- 12:46 AM
- Posts
- 218
- 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
- ASUS Laptop Zenbook Pro 14
- CPU
- Intel Core i9-13900H 2.6 GHz, 24MB 14 cores 20 threads
- Memory
- 32GB DDR5
- Graphics Card(s)
- NVIDIA GeForce RTX 4060 and Intel Iris Xe Graphics
- Monitor(s) Displays
- 14.5" 2.8K OLED 16:10 120Hz 400nits
- Screen Resolution
- 2880 x 1800 pixels
- Hard Drives
- 1TB M.2 NVMe™ PCIe® 4.0 Performance SSD
- Mouse
- Bluetooth
- Browser
- Microsoft Edge
- Antivirus
- McAfee , Malwarebytes , Ccleaner