2017-02-14 51 views
0

我正在寫這個批處理腳本,但是如果文件擴展名的所有文件都存在,它就會去查看,即使文件存在。我在這裏先向您的幫助表示感謝!找到具有相同擴展批處理腳本的多個文件

@echo off 
if not exist C:\Users\%USERNAME%\Desktop\workBackup (
    ::creates new folder 'workBackup' 
    mkdir C:\Users\%USERNAME%\Desktop\workBackup 
) 

set TIMESTAMP=%DATE:~4,2%%DATE:~7,2%%DATE:~10,4% 

if not exist C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP% (
    ::creates new folder to put work into 
    mkdir C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP%  
) 

if not exist C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP%\logs (
    ::creates logs folder 
    mkdir C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP%\logs 
) 

if exist C:\User\%USERNAME%\Documents\workspace\out\log\*.xlsx (
    ::moves all xlsx files to workBackup folder 
    move "C:\User\%USERNAME%\Documents\workspace\out\log\"*.xlsx C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP%\ 
) else (
    ::exits if file no files are found 
    echo "Files not found" 
    exit /b 
) 
if exist C:\User\%USERNAME%\Documents\workspace\out\log\*.xlsx (
    ::moves all log files to workBackup folder 
    move "C:\Users\%USERNAME%\Documents\workspace\out\log\"*.log C:\Users\%USERNAME%\Desktop\workBackup\%TIMESTAMP%\logs 
) else (
    ::exits if file no files are found 
    echo "Files not found" 
    exit /b 
) 

回答

0

有幾件事情提

  • 創建一個文件夾結構時,最深的一個將意味着其他
  • 日期格式爲每個用戶設置,從WMIC
  • 更好的獲取日期
  • 不測試,製作並壓制最終的錯誤消息。
  • 繞整個路徑創建瓦爾
  • 把雙引號不僅是

@echo off 
for /f %%A in ('wmic os get LocalDateTime^|findstr ^^[0-9]') do Set _DT=%%A 
Set yy=%_DT:~0,4%&Set MM=%_DT:~4,2%&Set dd=%_DT:~6,2% 

Set "WBu=C:\Users\%USERNAME%\Desktop\workBackup" 
Set "WBuDT=%WBu%\%dd%%MM%%yy%" 
:: or reverse day and month %MM%%dd%%yy% 
Set "WSpOL=C:\Users\%USERNAME%\Documents\workspace\out\log" 

mkdir "%WBuDT%\logs" 2>NUL 

::moves all xlsx files to workBackup folder 
move "%WSpOL%\*.xlsx" "%WBuDT%\" 2>NUL||(Echo "%WSpOL%\*.xlsx" not found&Exit /b) 

::moves all log files to workBackup folder 
move "%WSpOL%\*.log" "%WBuDT%\logs\" 2>NUL||(Echo "%WSpOL%\*.log" not found&Exit /b) 
+0

哇部分減少容易出錯冗餘,感謝所有的反饋和幫助。明天當我有我的系統時,我會試試這個! – Glen

+0

剛試過,它仍然無法找到文件。我通過評論移動命令嘗試了兩種類型。任何其他想法? – Glen

+0

有一個錯字(用戶缺少s)另外我在這裏做了一個測試,創建了所有的文件夾和批處理作品。 – LotPings

相關問題