CMD to delete 'autorecovered' files from c:


  1. Posts : 868
    Windows 10 x64
       #1

    CMD to delete 'autorecovered' files from c:


    What would be the cmd instruction to delete files on
    C: including
    'autorecovered' in the name and have
    extension .xlsb

    So, files that would show up after:

    C:\>dir /s *autorecovered*.xlsb

    They show up in various sub folders within:
    C:\Users\UserName\AppData\Roaming\Microsoft\Excel

    Thanks.
      My Computer


  2. Posts : 4,187
    Windows 11 Pro, 22H2
       #2

    Code:
    del *autorecovered*.xlsb /s
      My Computers


  3. Posts : 868
    Windows 10 x64
    Thread Starter
       #3

    hsehestedt said:
    Code:
    del *autorecovered*.xlsb /s
    Thanks!

    I wanted to edit my question, your reply came too soon

    My 'additional' question would have been

    and how to delete the empty folders thereafter (IF at all possible...)

    However, 1 folder (XLSTART) and 1 file (Excel15.xlb) may -not- be deleted.
    they are updated each time at Excel launch.

    If it is too complicated, then let it rest.

    CMD to delete 'autorecovered' files from c:-snagit-10072021-082412.png
      My Computer


  4. Posts : 4,187
    Windows 11 Pro, 22H2
       #4

    A challenge?

    I'll see if I can come up with a solution, but I won't make any guarantees. Hopefully it's not urgent. It's 2AM here and I'll work on this in the morning, unless I can't sleep.
      My Computers


  5. Posts : 868
    Windows 10 x64
    Thread Starter
       #5

    No, it isn't urgent.

    I am also seeking on Internet as well.
    So far no luck, that is to say, not without additional 'programming' or using a tool like 'DelEmpty.exe'.

      My Computer


  6. Posts : 4,187
    Windows 11 Pro, 22H2
       #6

    EDIT: saved this post too quickly. I want to give credit where it is due. This link explains what I am doing below:

    One-line batch script to delete empty directories | The Old New Thing (microsoft.com)

    As so often happens, I think I found a solution quicker than expected.

    I have not put this through much testing so please try it on some sample data or a copy of your data first to make sure it works as expected.

    1) Copy the 2 lines below into a text file, and call it something like DeleteFiles.bat
    Code:
    del *autorecovered*.xlsb /s
    for /f "usebackq delims=" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"
    2) Place this file in the location where you want to delete the the *autorecovered*.xlsb files. This file will operate on that folder and all subdirectories.
    3) Double-click the batch file to run it.

    How it works: The first line scans the entire directory tree and deletes files matching the pattern *autorecovered*.xlsb. If such a file exists it is deleted.

    The second line locates empty folders and deletes them. Note that the 2nd line runs after all the files matching *autorecovered*.xlsb are deleted so if a folder becomes empty by deleting any files matching that pattern, or if the folder was already empty, it will be deleted.

    This was a really fast stab at this and I think it should work fine, but please do let me know if there are any difficulties.
      My Computers


  7. Posts : 868
    Windows 10 x64
    Thread Starter
       #7

    orig text was partially wrapped


    Thanks. I also found this usebackq thing, but assumed it should be used in some programming language whatever.
    I don't have any expertise on such thing, so I skipped it.

    That said, I gave it a try on a test drive, to see if it would work.
    Copied the xlsb files and folders to another location. launched the batch, but nothing happened.
    I then tried just doing the 'del *autorecovered* .xlsb /s' thing, but got an 'Access is denied'-error.
    That must be the reason for the fact that nothing happened.
    Add /f parameter, that went fine. So: del *autorecovered* .xlsb /s /f
    Also the subfolders were deleted. That went fine as well.

    Now I already have a .bat file in the startup folder, that deletes all the
    *.doc*, *.xls*, *.jpg, etc. as well as all the microsoft *.lnk files in Windows and Office \Recent folder.

    Those are very simple lines like:
    del C:\Users\username\AppData\Local\Temp\*.doc*
    del C:\Users\username\AppData\Local\Temp\*.xls*
    del C:\Users\username\AppData\Local\Temp\*.jpg
    del C:\Users\username\AppData\Local\Microsoft\Office\UnsavedFiles\*.asddel C:\Users\username\AppData\Roaming\Microsoft\Excel\*autorecovered*.xlsb /s /f
    rem for /f "usebackq delims=" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"

    The delete.bat with the usebackq line requires to be in the \Excel folder on C:

    whereas 'my' deletefiles.bat is stored in the rootfolder (this is tricky of course)

    Not sure how to solve this. Run a batch within a batch?

    or, after the line with *.asd
    add
    cd\Users\username\AppData\Roaming\Microsoft\Excel
    del *autorecovered* .xlsb /s /f
    for /f "usebackq delims=" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"


    No idea, to be honest.

    Thanks!

    - - - Updated - - -


    11-07-2021
    Today I discovered that subfolders in : C:\Users\username\AppData\Roaming\Microsoft\Excel are being updated (modified date stamp updated) after boot, even though nothing of Office was launched. Checked and found links (.lnk) to existing files and these links were updated for one reason or the other.
    Those files are not 'autorecovered' but show the normal names.

    Now, back to the question in my 2nd post above, I think I have solved it with a workaround.
    copy XLSTART folder and Excel15.xlb to a temp folder

    It definitely doesn't look nice (better: it looks horrible), but I figure I have it covered this way:

    Code:
    rem create a temp folder
    d:
    cd\
    cd Downloads
    md Exceltemp
    rem copy files from \Excel on C: to temp folder
    ROBOCOPY C:\Users\UserName\AppData\Roaming\Microsoft\Excel\XLSTART\ d:\DOWNLOADS\Exceltemp\XLSTART
    COPY C:\Users\UserName\AppData\Roaming\Microsoft\EXCEL\Excel15.xlb d:\DOWNLOADS\Exceltemp
    rem remove subfolders in \Excel on C:
    c:
    cd\Users\UserName\AppData\Roaming\Microsoft\Excel\
    del * /s /q /f
    rmdir /s /q C:\Users\UserName\AppData\Roaming\Microsoft\Excel\
    rem restore files/folders from temp folder
    d:
    cd\
    robocopy d:\downloads\exceltemp\XLSTART C:\Users\UserName\AppData\Roaming\Microsoft\Excel\XLSTART
    copy d:\downloads\exceltemp\excel15.xlb C:\Users\UserName\AppData\Roaming\Microsoft\Excel\
    rem delete temp folder
    cd\downloads\exceltemp
    del * /s /q /f
    cd\
    rmdir /s /q d:\downloads\exceltemp
    Last edited by tfwul; 11 Jul 2021 at 23:46.
      My Computer


  8. Posts : 16,949
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #8

    tfwul said:
    ... how to delete the empty folders thereafter (IF at all possible...)

    However, 1 folder (XLSTART) and 1 file (Excel15.xlb) may -not- be deleted.
    they are updated each time at Excel launch.
    Never try to delete the XLSTART folder. Excel needs it.

    Denis
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 02:44.
Find Us




Windows 10 Forums