AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 571806
Accepted
DextrousDave
DextrousDave
Asked: 2014-02-04 03:56:05 +0800 CST2014-02-04 03:56:05 +0800 CST 2014-02-04 03:56:05 +0800 CST

批处理脚本适用于 Windows 7,但不适用于 Windows Server 2008

  • 772

美好的一天

我有以下批处理脚本循环遍历包含 .sql 文件的文件夹。当它找到一个带有今天日期时间戳的 .sql 文件时,它会将该文件复制到一个新目录中。

@echo off
setlocal enableextensions enabledelayedexpansion

set "currentDate=%date:~0,10%"
    for %%g in ("c:\mfa\*.sql") do (
     set "fileDate=%%~tg"
     set "fileDate=!fileDate:~0,10!"
     if "!fileDate!"=="%currentDate%" (
        copy "%%~fg" "c:\newLocation"
     )
    )

我的问题:

这在 Windows 7 上很好用,但在 Windows Server 2008 上不行。当我在 Win7 上回显 filedate 变量时,它会为我提供保存在 !fileDate! 中的时间戳!价值。但是当我回显!fileDate!在 Windows Server 2008 中,它返回:ECHO 已关闭。

即使我删除了延迟扩展,这仍然不起作用。

为什么它不能在 Server 2008 上运行?

===================== 更新 -

Powershell 错误

The term 'test.ps1' is not recognized as the name of a cmdlet, function, script file, or operable pro
elling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:9
+ test.ps1 <<<<
    + CategoryInfo          : ObjectNotFound: (test.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
windows-server-2008
  • 1 1 个回答
  • 808 Views

1 个回答

  • Voted
  1. Best Answer
    krisFR
    2014-02-04T05:01:22+08:002014-02-04T05:01:22+08:00

    我同意 MDMarra 关于使用 Powershell 的评论。

    我们在 2014 年,您的平台是 Windows 2008 Server...所以我强烈建议您考虑 Batch 有点“过时”...

    使用 Powershell,如下所示:

    $today=Get-Date -format d
    $files=Get-ChildItem "C:\mfa" -Filter *.sql
    foreach ($file in $files)
    {
      $filename=$file.FullName
      $dateCreated=$file.CreationTime | Get-Date -format d
      $dateModified=$file.LastWriteTime | Get-Date -format d
      write-output "Today is : $today"
      write-output "Scanning file : $filename"
      write-output "Modified : $dateModified"
      write-output "Created : $dateCreated"
      if($dateCreated -eq $today)
      {
        copy-item $filename c:\newLocation
      }
      write-output "---------------------------------------------"
    }
    

    假设在创建日期进行比较。要与上次修改日期进行比较,请使用LastWriteTime而不是CreationTime.

    • 3

相关问题

  • 文件复制到分支机构

  • 对于 ASP.Net 应用程序,Windows 64 位相对于 32 位的主要优势是什么?

  • Windows Server 2008 Hyper-V 虚拟化服务器的最佳 RAID 配置?

  • 远程连接 sql server 不工作,但如果防火墙禁用它呢?

  • 无法从 SQL Server 2008 备份数据库

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve