If Exist then Delete

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
CovertCodger
Posts: 1
Joined: 28 Feb 2023 04:56

If Exist then Delete

#1 Post by CovertCodger » 28 Feb 2023 05:03

I have a folder on my E drive named XLK_WorkSheets2023.
Prior to moving files from F:\Finances\CSOB\XLK_WorkSheets2023 to E:\XLK_WorkSheets2023 I need to have the *.xlk files deleted.
Then I need to move (actually move and not leave) the *.xlk files from F:\Finances\CSOB\XLK_WorkSheets2023 to E:\XLK_WorkSheets2023.
I have tried many different iterations of move and if exist then delete and nothing seems to work.
Before this is done I run a batch file that does the following and it works quite well, actually moving the *.xlk files from the indicated folders to F:\Finances\CSOB\XLK_WorkSheets2023.
Here then is the batch file that actually works quite well:
@echo off
move F:\Finances\CSOB\2023\*.xlk F:\Finances\CSOB\XLK_WorkSheets2023
move F:\Finances\CSOB\*.xlk F:\Finances\CSOB\XLK_WorkSheets2023
move F:\Dwight\Memoirs\Docs\dodge\Root\Docs\2023\*.xlk F:\Finances\CSOB\XLK_WorkSheets2023
move "F:\Dwight\In The Event Of My Death\*.xlk" "F:\Finances\CSOB\XLK_WorkSheets2023"
move F:\Finances\CSOB\NewCalendars\*.xlk F:\Finances\CSOB\XLK_WorkSheets2023
move F:\Data\Documents\Cooking\*.xlk F:\Finances\CSOB\XLK_WorkSheets2023
move F:\Dwight\Memoirs\Docs\dodge\Root\Excel\*.xlk F:\Finances\CSOB\XLK_WorkSheets2023

Any help writing a batch file that does what I need would be much appreciated.
And if it is possible that all this can be done with one batch file that would be impressive.

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: If Exist then Delete

#2 Post by miskox » 28 Feb 2023 06:41

Add

Code: Select all

del /f /q F:\Finances\CSOB\XLK_WorkSheets2023\*.xlk
if you want to delete files first.

Saso

Post Reply