Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Generic User Avatar

If Exist then Delete


  • Please log in to reply
2 replies to this topic

#1 CovertCodger

CovertCodger

  •  Avatar image
  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:05:54 AM

Posted 28 February 2023 - 05:30 AM

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.


BC AdBot (Login to Remove)

 


#2 Chris Cosgrove

Chris Cosgrove

  •  Avatar image
  • Global Moderator
  • 28,257 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Scotland
  • Local time:05:54 AM

Posted 28 February 2023 - 10:46 AM

First of all I have say that I do not understand this line in your post -

 

"Prior to moving files from F:\Finances\CSOB\XLK_WorkSheets2023 to E:\XLK_WorkSheets2023 I need to have the *.xlk files deleted."

 

This suggests that the first thing to do is to delete the files, I would have thought that if you did that there would be no files left to move.

 

The next thing is that the batch file as quoted in your post is moving files between two locations on F:\, not from F:\ to E:\ . And finally, if I remember my DOS correctly, a MOVE command only works fully between locations on the one drive. For example, if moving files from F:\Black to F:\ White then the files will appear in White and be gone from Black but if using MOVE between different drives the command converts to a copy/paste operation and the original files remain in their original locations. This would explain why you are still left with the files in their original locations.

 

Your batch file will copy the files to the specified folders in E:\ but I believe you will have to go back to F:\  to remove them. If you are moving all the ..XLK files in F:\ to E:\ then something as simple as 'del F:\ *.xlk would do the job.

 

Chris Cosgrove



#3 CovertCodger

CovertCodger
  • Topic Starter

  •  Avatar image
  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:05:54 AM

Posted 28 February 2023 - 11:50 AM

I hope I can clarify with the following. I may have messed up my original post.

 

Yes, it is true, several files are being moved from various locations on the F drive into this specific folder - F:\Finances\CSOB\XLK_WorkSheets2023. But that is intentional to keep these files from being copied at the end of the week via my use of GoodSync to my storage disks. I do not need or want multiple copies taking up precious storage space thus is why ultimately I only need at any given time two complete sets. One on the E drive @ E:\XLK_WorkSheets2023 and the second on my initial external storage disk which then gets cloned to 2 more disks. Redundancy is the word of the day! Furthermore when these files are moved from these various locations on the F drive to F:\Finances\CSOB\XLK_WorkSheets2023 they actually do disappear from the original F drive locations.

 

First the indicated files are moved as shown here:

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

Next, from previous actions, these same named files existing in E:\XLK_WorkSheets2023 need to be deleted.

When that is done then the newer files recently brought into F:\Finances\CSOB\XLK_WorkSheets2023 need to be moved to E:\XLK_WorkSheets2023. (and I do mean moved so they no longer exist in F:\Finances\CSOB\XLK_WorkSheets2023)

I hope this clarifies my intent.

 

Currently I run a combination of bat files and excel vba to get this done.

First bat file run:

@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

 

Second bat file run:

@echo off

move F:\Finances\CSOB\XLK_WorkSheets2023\*.xlk E:\XLK_WorkSheets2023

 

Third is the excel vba:

Sub Delete_Files()

Kill "E:\XLK_WorkSheets2023\*.xlk"

'This will delete all xlk files in this folder

End Sub

 

This all works very well, leaving no original files in F:\Finances\CSOB\XLK_WorkSheets2023 when all is said and done.

Essentially I would like all of this to flow seamlessly from one bat file if possible, or even from excel vba if that is also possible.

I looked into vba for moving files but could not find anything useful.

Thank you for bearing with me, much appreciated.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users