选择要用作变量的第一个文件的名称

时间:2015-07-24 19:45:53

标签: file batch-file pdf

如何查看PDF是否在文件夹中,然后将第一个PDF名称设置为变量,以便我可以打开它并移动它。每种PDF都有所不同。所以总会有不同名字的新词。

`@echo off
:start
SETLOCAL enableextensions
start PP15Timesheet.pdf
timeout 5 > NUL
start select.vbs
start copy.vbs
timeout 2 > NUL

timeout 2 > NUL

timeout 5 > NUL
for /F %%g in ('
  wmic OS get LocalDateTime /value^|findstr "="
  ') do for /F %%G in ("%%g") do set "_%%G"
echo %_LocalDateTime:~0,14%
type NUL > TextFiles\%_LocalDateTime:~0,14%.txt
start TextFiles\%_LocalDateTime:~0,14%.txt
timeout 2 > NUL
start close.vbs
start window.vbs
start paste.vbs
start save.vbs
timeout 2 > NUL
start close.vbs
start enter.vbs

move /-y "PP15Timesheet.pdf" "\OldTimesheets\"

timeout 2> NUL
goto start`

我只需要在顶部来确定它是否需要运行循环或是否应该等到它再次检查。当我在这里时,我的移动代码无效。多数民众赞成我如何确保我没有两次阅读相同的PDF。谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

如果我了解您的目标(处理当前目录中的所有pdf文件),也许下一个代码段可以提供帮助:

@echo off
SETLOCAL enableextensions
for %%x in (*.pdf) do (
    set "_pdfname=%%x"
    call :doAllWork
)
goto :eof

:doAllWork
start %_pdfname%
timeout 5 > NUL
start select.vbs
start copy.vbs
timeout 2 > NUL
timeout 2 > NUL
timeout 5 > NUL
for /F %%g in ('
  wmic OS get LocalDateTime /value^|findstr "="
  ') do for /F %%G in ("%%g") do set "_%%G"
echo %_LocalDateTime:~0,14%
type NUL > TextFiles\%_LocalDateTime:~0,14%.txt
start TextFiles\%_LocalDateTime:~0,14%.txt
timeout 2 > NUL
start close.vbs
start window.vbs
start paste.vbs
start save.vbs
timeout 2 > NUL
start close.vbs
start enter.vbs

rem                    v                 remove this backslash?
move /-y "%_pdfname%" "\OldTimesheets\"
rem                    ^                 remove this backslash?

timeout 2> NUL
goto :eof

资源(必读):