UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Kill Files That Begin With ~$, Access 2016    
 
   
aggiemarine07
post Jan 22 2020, 12:59 PM
Post#1



Posts: 88
Joined: 7-January 11



So I have a weird issue that I thought I resolved with the below code but it still continues to persist:

CODE
'kill all temp files
Dim MyFile As String
MyFile = Dir$(CurrentProject.Path & "\PLOGS sharepoint\~$*")
Do While MyFile <> ""
    KillProperly CurrentProject.Path & "\PLOGS sharepoint\" & MyFile
    MyFile = Dir$(CurrentProject.Path & "\PLOGS sharepoint\~$*")
Loop


A little backstory, I have a piece of code right after the above that copies a bunch of files and folders to a network share. However, lately I had been getting a Windows prompt that says "an unexpected error is keeping you from copying the file. Error 0x800700DE: The file type being saved or retrieved has been blocked. Filename: ~$Cost Change Sheet.xlsb" The weird thing is that this file is closed and had been closed for a few days now. Does anyone have an idea of how to fix this? Thanks in advance!
Go to the top of the page
 
theDBguy
post Jan 22 2020, 02:20 PM
Post#2


UA Moderator
Posts: 77,524
Joined: 19-June 07
From: SunnySandyEggo


Hi. When you get the error, try doing it manually to see if you get a better error message.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
aggiemarine07
post Jan 22 2020, 03:16 PM
Post#3



Posts: 88
Joined: 7-January 11



@theDBguy - thats the other weird thing, they dont show in the folders at all; even when i enable to show all hidden files/folders in File Explorer. Command line also does not show any file present.
Go to the top of the page
 
WildBird
post Jan 22 2020, 04:55 PM
Post#4


UtterAccess VIP
Posts: 3,724
Joined: 19-August 03
From: Auckland, Little Australia


They look like temp files, and I would add error handling to deal with them.

If you cant see them in explorer or via command line, likely you dont need them, so if you cant delete them, ignore them I would say.

What is your code for KillProperly?




--------------------
Beer, natures brain defragging tool.
Go to the top of the page
 
aggiemarine07
post Jan 22 2020, 05:03 PM
Post#5



Posts: 88
Joined: 7-January 11



@WildBird - how would I got about deleting them? I am using FSO to move the files from one folder to another

This is the KillProperly sub that im calling to try and delete the files:
CODE
Option Compare Database

Public Sub KillProperly(Killfile As String)
    If Len(Dir$(Killfile)) > 0 Then
        SetAttr Killfile, vbNormal
        Kill Killfile
    End If
End Sub


This is the code I am using to copy the files from one place to another:

CODE
Option Compare Database

Public Declare Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Public Const FO_COPY = &H2
Public Const FOF_SIMPLEPROGRESS = &H100

Public Type SHFILEOPSTRUCT
    hWnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Long
    hNameMappings As Long
    lpszProgressTitle As Long
End Type

Public Sub VBCopyFolder(ByRef strSource As String, ByRef strTarget As String)
    Dim op As SHFILEOPSTRUCT

    With op
        .wFunc = FO_COPY
        .pTo = strTarget
        .pFrom = strSource
        .fFlags = FOF_SIMPLEPROGRESS
    End With

    '~~> Perform operation
    SHFileOperation op
End Sub
Go to the top of the page
 
WildBird
post Jan 22 2020, 08:58 PM
Post#6


UtterAccess VIP
Posts: 3,724
Joined: 19-August 03
From: Auckland, Little Australia


Got a meeting to go to, will try and remember later though, if no one else jumps in!

Cheers

--------------------
Beer, natures brain defragging tool.
Go to the top of the page
 
WildBird
post Jan 22 2020, 10:43 PM
Post#7


UtterAccess VIP
Posts: 3,724
Joined: 19-August 03
From: Auckland, Little Australia


CODE
Function KillProperly(ByVal strFileName As String) As Boolean
'Date:          Thursday, 23 January 2020 2:57:16 PM
'Author:        Stephen Cooper
'Email:         XXXXXXXXXXXXXXXXXX.com
'Ph:
'In parameters
'Output
'Description:   Will delete a file
'Calls:
'Notes:
'Example:

On Error GoTo HandleError:

KillProperly = True

Dim intMouseType As Integer
Dim strErrorMsg As String
Dim varReturn As Variant
Dim objFSO As Object

intMouseType = Screen.MousePointer

DoCmd.Hourglass True

Set objFSO = CreateObject("Scripting.FileSystemObject")

SetAttr strFileName, vbNormal

If objFSO.FileExists(strFileName) Then
    objFSO.DeleteFile strFileName
Else
    'This will return True by default if the file doesn't exist.
    'Can set it to false and see how you can use the return value. Not sure what you want to do, or how you want to handle it.
    KillProperly = False
    GoTo ExitHere
End If 'objFSO.FileExists(strFileName)

ExitHere:
On Error Resume Next
'Close all recordsets etc here
varReturn = SysCmd(acSysCmdClearStatus)
Screen.MousePointer = intMouseType
Set objFSO = Nothing
Exit Function

HandleError:
Select Case Err.Number
Case 70
    'File is open
    KillProperly = False
    GoTo ExitHere
Case Else
    'LogError "KillProperly|" & CurrentProject.Name & "|" & strErrorMsg & "|" & Err.Number & " - " & Err.Description & "| Line number " & Erl
    MsgBox strErrorMsg & " " & Err.Number & " " & Err.Description, vbInformation, "Error"
    KillProperly = False
    Resume ExitHere
End Select


End Function


--------------------
Beer, natures brain defragging tool.
Go to the top of the page
 
aggiemarine07
post Jan 24 2020, 06:45 PM
Post#8



Posts: 88
Joined: 7-January 11



@WildBird - thanks! I wont get a chance to try it until Wednesday this next week. I'll report back then!
Go to the top of the page
 
aggiemarine07
post Jan 29 2020, 02:21 PM
Post#9



Posts: 88
Joined: 7-January 11



@WildBird - Worked like a charm; thanks!
Go to the top of the page
 
WildBird
post Jan 29 2020, 04:56 PM
Post#10


UtterAccess VIP
Posts: 3,724
Joined: 19-August 03
From: Auckland, Little Australia


QUOTE
@WildBird - Worked like a charm; thanks!


Cheers! Good luck with it.

--------------------
Beer, natures brain defragging tool.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    24th February 2020 - 07:33 PM