Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am currently trying to get a list of items saved from a profile on an old machine and then sent to the new machine and profile, being that the profile is the same.

On Windows 7 the location %AppData%MicrosoftSticky Notes stores the .snt for sticky notes. That location exists natively all the way to Windows 10 1511.

On Windows 10 1607 it has been moved to %LocalAppData%PackagesMicrosoft.MicrosoftStickyNotes_8wekyb3d8bbweLocalState" and changed toplum.sqlite`.

If you upgraded from anything earlier than Windows 10 1607 it will have made a Legacy folder with ThresholdNotes.snt in it and that will convert over to the plum.sqlite.

I am writing a nested .bat which will:

IF old sticky notes location on the new computer exists
? ? check for pulled .snt file, then copy over
ELSE
? ? check for pulled .snt file

IF new legacy location not exist
? ? create then copy and rename .snt to convert
ELSE
? ? copy,rename

IF old sticky notes location not exist
? ? then check for new .sqlite file
ELSE
? ? copy new file to new location

Otherwise say there are none detected.

But it seems I may be writing it wrong or something because I have placed a pause in the .bat but it just closes immediately when ran.

Here is the current Pull part where it retrieves the .snt or .sqlite. Variables first and then the actual action part.

REM Saves Users Sticky Notes
Set StickyNotes="%userprofile%AppDataRoamingMicrosoftSticky NotesStickyNotes.snt"
Set FlashStickyNotes="%~dp0%USERNAME%StickyNotes"

REM Saves Users Sticky Notes From Win 10 1607+
Set StickyNotesWin10="%userprofile%AppDataLocalPackagesMicrosoft.MicrosoftStickyNotes_8wekyb3d8bbweLocalStateplum.sqlite"
Set FlashStickyNotesWin10="%~dp0%USERNAME%StickyNotesWin10"


Title Pulling StickyNotes
if exist %StickyNotes% ( xcopy %StickyNotes% %FlashStickyNotes% /f /y ) ELSE if exist %StickyNotesWin10% ( 
xcopy %StickyNotesWin10% %FlashStickyNotesWin10% /f /y ) else Echo "No Sticky Notes Detected"

^^This part seems to work just fine and not have any problems

Here's the Push part and this is where I seem to have trouble but maybe its formatting? Variables first and then the actual action part.

REM Saves Users Sticky Notes
Set StickyNotes="%userprofile%AppDataRoamingMicrosoftSticky Notes"
Set FlashStickyNotes="%~dp0%USERNAME%StickyNotesStickyNotes.snt"

REM Saves Users Sticky Notes From Win 10 1607+
Set StickyNotesWin10="%userprofile%AppDataLocalPackagesMicrosoft.MicrosoftStickyNotes_8wekyb3d8bbweLocalState"
Set FlashStickyNotesWin10="%~dp0%USERNAME%StickyNotesWin10plum.sqlite"

Title Pushing StickyNotes
REM if old sticky notes location on the new computer exists, then check for pulled .snt file, then copy over ELSE
REM if new sticky notes location exists, check for pulled .snt file, if new legacy location not exist, then create and then copy and rename .snt to convert, else copy,rename
REM if old sticky notes location not exist, then check for new .sqlite file, if exist then copy new file to new location ELSE
REM otherwise say there are none detected
IF exist "%userprofile%AppDataRoamingMicrosoftSticky Notes"( IF exist "%FlashStickyNotes%"( xcopy %FlashStickyNotes% %StickyNotes% /F /Y ) 
IF exist "%userprofile%AppDataLocalPackagesMicrosoft.MicrosoftStickyNotes_8wekyb3d8bbweLocalState"(
    IF exist "%FlashStickyNotes%"(
        IF not exist "%userprofile%AppDataLocalPackagesMicrosoft.MicrosoftStickyNotes_8wekyb3d8bbweLocalStateLegacy"(
            mkdir "%userprofile%AppDataLocalPackagesMicrosoft.MicrosoftStickyNotes_8wekyb3d8bbweLocalStateLegacy"
            xcopy %FlashStickyNotes% "%userprofile%AppDataLocalPackagesMicrosoft.MicrosoftStickyNotes_8wekyb3d8bbweLocalStateLegacyThresholdNotes.snt" /F /Y
        ) else IF exist "%userprofile%AppDataLocalPackagesMicrosoft.MicrosoftStickyNotes_8wekyb3d8bbweLocalStateLegacy"((
            xcopy %FlashStickyNotes% "%userprofile%AppDataLocalPackagesMicrosoft.MicrosoftStickyNotes_8wekyb3d8bbweLocalStateLegacyThresholdNotes.snt" /F /Y
        )
    )
) else IF not exist "%StickyNotes%" (
    IF exist %FlashStickyNotesWin10% (
    copy %FlashStickyNotesWin10% %StickyNotesWin10% /Y
    )
)
) ELSE Echo "No Sticky Notes Detected" 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
153 views
Welcome To Ask or Share your Answers For Others

1 Answer

Besides the syntax issues you have (missing SPACE between the conditional expression and the opening parenthesis, if exist "%somepath%" (; and even two opening parentheses once, if exist "%somepath%"((), I believe your problem is the logic and the misleading way of indentation and parenthesising you are using.

Let us assume the following code snippet:

@echo off
set "X=" & set "Y="
set /P X="X="
set /P Y="Y="

if defined X if defined Y (
    echo X=%X%, Y=%Y%
) else echo X and/or Y is empty

What would you expect to be returned in case variable X is empty?

Let us take a look to the same code in function but differently written (skipping the variable definitions/prompts this time):

if defined X (
    if defined Y (
        echo X=%X%, Y=%Y%
    ) else (
        echo X and/or Y is empty
    )
)

You may now notice that nothing is returned in case of an empty variable X.

The fixed code might look like this:

if defined X (
    if defined Y (
        echo X=%X%, Y=%Y%
    ) else (
        echo Y is empty
    )
) else (
    echo X is empty, Y not checked
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...