用于搜索文件夹中文件的批处理文件

时间:2021-10-25 23:58:07

I need a bat file to search excel files in a folder. It should do the following

我需要一个bat文件来搜索文件夹中的excel文件。它应该做到以下几点

  1. search in a folder
  2. 在文件夹中搜索

  3. looks for excel files after created date
  4. 在创建日期后查找excel文件

  5. if it is older than system date deletes the excel file
  6. 如果它早于系统日期,则删除excel文件

  7. if not it runs a converter.js
  8. 如果不是它运行converter.js

Can any one help.

任何人都可以帮忙。

1 个解决方案

#1


0  

Here you go. Remove the echo's from the script once you see good output on the screen. Also, I'm not sure how you are running converter.js so you'll need to change that line to however you do it and if your file dates are in a different format, you'll have to re-arrange the "%MM%/%DD%/%YYYY%" too.

干得好。一旦在屏幕上看到良好​​的输出,就从脚本中删除回声。此外,我不确定你是如何运行converter.js所以你需要更改该行,但是如果你这样做,如果你的文件日期是不同的格式,你将不得不重新安排“% MM%/%DD%/%YYYY%“也是。

@echo off
setlocal enabledelayedexpansion

pushd "C:\location\of\files\"

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"

for /f "tokens=*" %%a in ('dir /o-d /b /tc *.xls') do (
  for /f "tokens=1" %%b in ("%%~ta") do (
    if "%%b" NEQ "%MM%/%DD%/%YYYY%" (
      echo del "%%a"
    ) ELSE (
      echo run converter.js
    )
  )
)
popd

#1


0  

Here you go. Remove the echo's from the script once you see good output on the screen. Also, I'm not sure how you are running converter.js so you'll need to change that line to however you do it and if your file dates are in a different format, you'll have to re-arrange the "%MM%/%DD%/%YYYY%" too.

干得好。一旦在屏幕上看到良好​​的输出,就从脚本中删除回声。此外,我不确定你是如何运行converter.js所以你需要更改该行,但是如果你这样做,如果你的文件日期是不同的格式,你将不得不重新安排“% MM%/%DD%/%YYYY%“也是。

@echo off
setlocal enabledelayedexpansion

pushd "C:\location\of\files\"

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"

for /f "tokens=*" %%a in ('dir /o-d /b /tc *.xls') do (
  for /f "tokens=1" %%b in ("%%~ta") do (
    if "%%b" NEQ "%MM%/%DD%/%YYYY%" (
      echo del "%%a"
    ) ELSE (
      echo run converter.js
    )
  )
)
popd