Skip to content
⌘ NSIS Forum Archive

Partial filename matching

8 posts

tbrady233#edited

Partial filename matching

Hi guys,

I'm working on a script that essentially needs to do the following:

If a file name in "$PROFILE\appdata\local\microsoft\outlook\roamcache" contains "AutoComplete" in the name, copy the file name to a variable.

I then need to rename another file using that variable. The file that needs to be re-named lives in $PROFILE\appdata\local\microsoft\outlook\autocomplete and also contains "AutoComplete" in the name.

I can't figure out how to use a wildcard to find a file that contains "AutoComplete" in it.

This is what I tried, but using a * as a wildcard doesn't work.


Section
${GetFileName} $PROFILE\appdata\local\microsoft\outlook\roamcache\*AutoComplete*.dat $R0

Rename $PROFILE\appdata\local\microsoft\outlook\Autocomplete\*AutoComplete*.dat $PROFILE\appdata\local\microsoft\outlook\Autocomplete\$R0

SectionEnd
Anders#
First off, your base directory should be $localappdata.

Use FindFirst and friends to find files and walk directory trees...
tbrady233#
Thanks!

This is what I came up with, but it doesn't seem to work as expected:

Section



FindFirst $0 $1 "$LOCALAPPDATA\microsoft\outlook\roamcache\Stream_AutoComplete*.dat"


FindFirst $R1 $R0 "$LOCALAPPDATA\microsoft\outlook\autocomplete\Stream_AutoComplete*.dat"



Rename "$LOCALAPPDATA\microsoft\outlook\autocomplete\$R0" "$LOCALAPPDATA\microsoft\outlook\roamcache\$1"
SectionEnd


The beginning of the file always starts with Stream_AutoComplete, and the rest of it is dynamic so it's always different depending on which Outlook profile you log into. I need the auto-complete entries on the new profile to be renamed to have the same name as the old one. Any help is much appreciated.
Anders#
Just saying something does not work is not that helpful. Use MessageBox to inspect the results from FindFirst and verify that they are sane.

Does it make sense to rename to something that already exists? May you want to rename the original file to "filename.bak" or something and then copy/move/rename the new replacement file.

I don't have Outlook so I don't know.
tbrady233#
Sorry, I should have been more specific. I tested with MessageBox and the results came back as I expected them. It looks like the problem is with the rename. It's sending the correct results to the $1 and $R0 variables, but the rename isn't working.


I have two separate scripts at hand, and the reason for them is we're doing a migration from exchange 2007 to 2016. The first script makes a copy of the users auto-complete .dat file, and places it in a folder in appdata\local\microsoft\outlook. This file contains all of their auto-complete data for Outlook. After the migration, their Outlook profile will be deleted, along with the Auto-complete file that lives in the default location. A new file will be populated, but it will be empty. The files have random names, and the only way to re-populate the users auto-complete data is to rename their old .DAT file so that it has the same name as the new .DAT file that was generated. As soon as you rename it and copy it back into the default location, their auto-complete entries will return to Outlook.

Hopefully that kind of makes sense haha.. I will be using SCCM to push these scripts out at a user level. I definitely appreciate the help since I'm super close to having this work now.
tbrady233#
I got it! It needed a /REBOOTOK added after the rename. Now the file is copied over with the correct name after a reboot. Thanks a ton!
Anders#
Just rename or delete the old file first, you don't need to reboot unless the file is in use by another application.