我目前正在尝试从旧计算机上的配置文件中获取保存的项目列表,然后将其发送到新计算机和配置文件,因为该配置文件是相同的。
在Windows 7上,位置%AppData%\Microsoft\Sticky Notes
存储了.snt
便签。该位置本身存在于Windows 10 1511中。
在Windows 10 1607上,它已移至%LocalAppData%\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState" and changed to
plum.sqlite`。
如果您从早于Windows 10 1607的任何内容进行升级,则会在其中生成一个Legacy
个文件夹,其中包含ThresholdNotes.snt
,并将转换为plum.sqlite
。
我正在编写一个嵌套的.bat
,它将:
如果新计算机上的旧便笺位置存在
检查已拉.snt
个文件,然后复制到ELSE
检查已拉.snt file
如果新遗留位置不存在
创建然后复制并重命名.snt
以转换为ELSE
复制,重命名
如果旧便签位置不存在
然后检查新的.sqlite
文件是否为ELSE
将新文件复制到新位置
否则说没有检测到。
但似乎我可能写错了什么或因为我在.bat
暂停了一下,但它在跑步时立即关闭。
以下是当前的Pull部分,用于检索.snt
或.sqlite
。首先是变量,然后是实际的动作部分。
REM Saves Users Sticky Notes
Set StickyNotes="%userprofile%\AppData\Roaming\Microsoft\Sticky Notes\StickyNotes.snt"
Set FlashStickyNotes="%~dp0%USERNAME%\StickyNotes"
REM Saves Users Sticky Notes From Win 10 1607+
Set StickyNotesWin10="%userprofile%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.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"
^^这部分似乎工作正常,没有任何问题
这是推送部分,这是我似乎遇到麻烦但可能是格式化的地方?首先是变量,然后是实际的动作部分。
REM Saves Users Sticky Notes
Set StickyNotes="%userprofile%\AppData\Roaming\Microsoft\Sticky Notes\"
Set FlashStickyNotes="%~dp0%USERNAME%\StickyNotes\StickyNotes.snt"
REM Saves Users Sticky Notes From Win 10 1607+
Set StickyNotesWin10="%userprofile%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\"
Set FlashStickyNotesWin10="%~dp0%USERNAME%\StickyNotesWin10\plum.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%\AppData\Roaming\Microsoft\Sticky Notes\"( IF exist "%FlashStickyNotes%"( xcopy %FlashStickyNotes% %StickyNotes% /F /Y )
IF exist "%userprofile%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\"(
IF exist "%FlashStickyNotes%"(
IF not exist "%userprofile%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\Legacy"(
mkdir "%userprofile%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\Legacy"
xcopy %FlashStickyNotes% "%userprofile%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\Legacy\ThresholdNotes.snt" /F /Y
) else IF exist "%userprofile%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\Legacy"((
xcopy %FlashStickyNotes% "%userprofile%\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\Legacy\ThresholdNotes.snt" /F /Y
)
)
) else IF not exist "%StickyNotes%" (
IF exist %FlashStickyNotesWin10% (
copy %FlashStickyNotesWin10% %StickyNotesWin10% /Y
)
)
) ELSE Echo "No Sticky Notes Detected"
答案 0 :(得分:1)
除了语法问题(在条件表达式和左括号之间缺少 SPACE ,if exist "%somepath%" (
;甚至两次打开括号,if exist "%somepath%"((
),我相信你的问题是你正在使用的缩进和括号的逻辑和误导方式。
让我们假设以下代码片段:
@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
如果变量X
为空,您希望返回什么?
让我们看看函数中的相同代码,但写的不同(这次跳过变量定义/提示):
if defined X (
if defined Y (
echo X=%X%, Y=%Y%
) else (
echo X and/or Y is empty
)
)
您现在可能会注意到,如果变量为空X
,则不会返回任何内容。
固定代码可能如下所示:
if defined X (
if defined Y (
echo X=%X%, Y=%Y%
) else (
echo Y is empty
)
) else (
echo X is empty, Y not checked
)
答案 1 :(得分:0)
REM OS before Vista have no LocalAppData variable
if not defined LocalAppData set "LocalAppData=%AppData%\..\Local"
REM Saves Users Sticky Notes
Set StickyNotes=%AppData%\Microsoft\Sticky Notes\StickyNotes.snt
Set FlashStickyNotes=%~dp0%USERNAME%\StickyNotes
REM Saves Users Sticky Notes From Win 10 1607+
Set StickyNotesWin10=%LocalAppData%\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.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"
这是拉动部分。只是通过引用和使用来改变路径
std变量。如果需要,添加%LocalAppData%
未定义的检查
并在Vista之前在操作系统上使用替代品。
REM OS before Vista have no LocalAppData variable
if not defined LocalAppData set "LocalAppData=%AppData%\..\Local"
REM Saves Users Sticky Notes
Set StickyNotes=%AppData%\Microsoft\Sticky Notes
Set FlashStickyNotes=%~dp0%USERNAME%\StickyNotes\StickyNotes.snt
REM Saves Users Sticky Notes From Win 10 1607+
Set StickyNotesWin10=%LocalAppData%\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState
Set FlashStickyNotesWin10=%~dp0%USERNAME%\StickyNotesWin10\plum.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 "%StickyNotes%" (
IF exist "%FlashStickyNotes%" (
xcopy "%FlashStickyNotes%" "%StickyNotes%" /F /Y
)
) else IF exist "%StickyNotesWin10%\" (
IF exist "%FlashStickyNotes%" (
IF not exist "%StickyNotesWin10%\Legacy" (
mkdir "%StickyNotesWin10%\Legacy"
xcopy "%FlashStickyNotes%" "%StickyNotesWin10%\Legacy\ThresholdNotes.snt" /F /Y
) else (
xcopy "%FlashStickyNotes%" "%StickyNotesWin10%\Legacy\ThresholdNotes.snt" /F /Y
)
)
) else (
IF exist "%FlashStickyNotesWin10%" (
copy "%FlashStickyNotesWin10%" "%StickyNotesWin10%" /Y
) else (
Echo "No Sticky Notes Detected"
)
)
文字路径用适当的变量替换。缩进使得一致
所以打开和关闭支架可以更容易配对。替换了过时的else if
检查
只有else
。
引用稍后完成的路径,允许在需要时扩展路径。
如果Echo "No Sticky Notes Detected"
,请确定您是否退出脚本。
如果您确实要退出,则可以使用:
>&2 Echo "No Sticky Notes Detected"
exit /b 1
所以echo返回stderr并以errorlevel 1退出。
代码未经过测试,请检查我的更改。