【问题标题】:xcopy batch file pst backupxcopy 批处理文件 pst 备份
【发布时间】:2013-03-08 11:03:44
【问题描述】:

我正在尝试构建一个批处理文件脚本,该脚本将从用户的“我的文档”文件夹中复制 Outlook.pst 文件并将其移动到我已映射为驱动器“B:\”的服务器

这是我目前的代码:

@echo on
xcopy "c:\Documents and Settings\%username%\My Documents\outlook.pst" "B:\PST\%username%\" -c -d -i -y
exit

该脚本专为 Windows XP 设计。

但是,当我在客户端计算机上运行此代码时,它不会复制 .pst 文件,它只是一遍又一遍地运行命令,直到我 Ctrl + C 它...

谢谢

【问题讨论】:

  • 只是出于好奇,您使用xcopy 而不是copy 有什么原因吗?

标签: file batch-file cmd


【解决方案1】:

如果我没记错的话,PST 文件的默认位置是%localappdata%\Microsoft\Outlook\。如果用户在多个位置有 PST 文件,他可能有多个同名的文件,只是在不同的文件夹中。好时光。

如果您的用户可能在 My Documents 以外的位置拥有 PST 文件,我建议您修改您的脚本,只做几个非常小的更改。

@echo off
setlocal enabledelayedexpansion
for /r "%userprofile%" %%I in (*.pst) do (

    rem avoid overwriting in case "outlook.pst" exists in two locations, for instance
    if exist "B:\PST\%username%\%%~nxI" (
        set cnt=000

        rem get count of files matching b:\pst\username\filename*.pst
        for /f %%a in ('dir "B:\PST\%username%\%%~nI*%%~xI" 2^>NUL ^| find " File(s) "') do (
            set "cnt=!cnt!%%a"
        )

        rem file of the same name will become filename001.pst, filename002.pst, etc.
        set "dest=%%~nI!cnt:~-3!%%~xI"

    rem otherwise leave the filename alone
    ) else set "dest=%%~nxI"
    set /P "=Copying !dest!... "<NUL
    copy "%%~fI" "B:\PST\%username%\!dest!"
    echo Done.
)

【讨论】:

    【解决方案2】:

    我希望使用 Windows XP 中的批处理文件将 Outlook.pst 从其 Microsoft 默认位置复制到记忆棒 我发现 xcopy 无法将 Outlook.pst 复制到记忆棒或我的文档中

    我现在分两步将它复制到 C:\ 然后到记忆棒

    它工作可靠

    【讨论】: