我讓chatgpt幫我寫了幾個(gè)批處理老是有些問題是我問的不對嗎Rose, [/2/23 10:08]用批處理寫一個(gè)強(qiáng)制刪除位于C盤Windows1目錄下的創(chuàng)建于5分鐘之內(nèi)生成的文件夾和文件ChatGPT CHAT, [/2/23 10:08]以下是一個(gè)可以實(shí)現(xiàn)您要求的批處理腳本:@echo offsetlocalset target_dir=C:Windows1for /f delims= %%a in ('dir /b /ad-h /t:c %target_dir% ^| findstr /l /c:<') do (set dir_path=%target_dir%%%afor /f delims= %%b in ('dir /b /a-d /t:c %dir_path% ^| findstr /l /c:<') do (set file_path=%dir_path%%%bsetlocal enableDelayedExpansionset file_create_time=!file_path:=!for /f usebackq tokens=1-6 delims=/: %%c in ('dir /tc !file_path! ^| findstr /l /c:<') do (set create_date=%%f-%%d-%%eset create_time=%%gset create_timestamp=!create_date!T!create_time!Z)setlocal disableDelayedExpansionset current_time=%date:~10,4%-%date:~4,2%-%date:~7,2T%time:~0,2%:%time:~3,2%:%time:~6,2%Zset /a time_diff=(%current_time:/=-%) - (%create_timestamp:/=-%)if !time_diff! leq 300 (echo Deleting file: !file_path!del /q !file_path!))rd /s /q !dir_path!)解釋:1. set target_dir=C:Windows1 - 設(shè)置目標(biāo)目錄的路徑。2. for /f delims= %%a in ('dir /b /ad-h /t:c %target_dir% ^| findstr /l /c:<') do ( - 遍歷目標(biāo)目錄下的所有子目錄,排除隱藏目錄,并使用 findstr 過濾出創(chuàng)建時(shí)間在當(dāng)前時(shí)間之前的目錄(即創(chuàng)建時(shí)間與當(dāng)前時(shí)間相差不超過5分鐘的目錄)。3. set dir_path=%target_dir%%%a - 獲取目錄的完整路徑。4. for /f delims= %%b in ('dir /b /a-d /t:c %dir_path% ^| findstr /l /c:<') do ( - 遍歷目錄下的所有文件,排除目錄,并使用 findstr 過濾出創(chuàng)建時(shí)間在當(dāng)前時(shí)間之前的文件。5. set file_path=%dir_path%%%b - 獲取文件的完整路徑。6. setlocal enableDelayedExpansion - 啟用延遲環(huán)境變量擴(kuò)展,以便在循環(huán)內(nèi)部設(shè)置變量。7. set file_create_time=!file_path:=! - 將文件路徑中的反斜杠替換為雙反斜杠,以便在 dir 命令中使用。8. for /f usebackq tokens=1-6 delims=/: %%c in ('dir /tc !file_path! ^| findstr /l /c:<') do ( - 獲取文件的創(chuàng)建時(shí)間,并將其轉(zhuǎn)換為 ISO我讓chatgpt幫我寫了幾個(gè)批處理老是有些問題是我問的不對嗎
發(fā)布:未知 文本批量工具
我讓chatgpt幫我寫了幾個(gè)批處理老是有些問題是我問的不對嗎Rose, [/2/23 10:08]用批處理寫一個(gè)強(qiáng)制刪除位于C盤Windows1目錄下的創(chuàng)建于5分鐘之內(nèi)生成的文件夾和文件ChatGPT CHAT, [/2/23 10:08]以下是一個(gè)可以實(shí)現(xiàn)您要求的批處理腳本:@echo offsetlocalset target_dir=C:Windows1for /f delims= %%a in ('dir /b /ad-h /t:c %target_dir% ^| findstr /l /c:<') do (set dir_path=%target_dir%%%afor /f delims= %%b in ('dir /b /a-d /t:c %dir_path% ^| findstr /l /c:<') do (set file_path=%dir_path%%%bsetlocal enableDelayedExpansionset file_create_time=!file_path:=!for /f usebackq tokens=1-6 delims=/: %%c in ('dir /tc !file_path! ^| findstr /l /c:<') do (set create_date=%%f-%%d-%%eset create_time=%%gset create_timestamp=!create_date!T!create_time!Z)setlocal disableDelayedExpansionset current_time=%date:~10,4%-%date:~4,2%-%date:~7,2T%time:~0,2%:%time:~3,2%:%time:~6,2%Zset /a time_diff=(%current_time:/=-%) - (%create_timestamp:/=-%)if !time_diff! leq 300 (echo Deleting file: !file_path!del /q !file_path!))rd /s /q !dir_path!)解釋:1. set target_dir=C:Windows1 - 設(shè)置目標(biāo)目錄的路徑。2. for /f delims= %%a in ('dir /b /ad-h /t:c %target_dir% ^| findstr /l /c:<') do ( - 遍歷目標(biāo)目錄下的所有子目錄,排除隱藏目錄,并使用 findstr 過濾出創(chuàng)建時(shí)間在當(dāng)前時(shí)間之前的目錄(即創(chuàng)建時(shí)間與當(dāng)前時(shí)間相差不超過5分鐘的目錄)。3. set dir_path=%target_dir%%%a - 獲取目錄的完整路徑。4. for /f delims= %%b in ('dir /b /a-d /t:c %dir_path% ^| findstr /l /c:<') do ( - 遍歷目錄下的所有文件,排除目錄,并使用 findstr 過濾出創(chuàng)建時(shí)間在當(dāng)前時(shí)間之前的文件。5. set file_path=%dir_path%%%b - 獲取文件的完整路徑。6. setlocal enableDelayedExpansion - 啟用延遲環(huán)境變量擴(kuò)展,以便在循環(huán)內(nèi)部設(shè)置變量。7. set file_create_time=!file_path:=! - 將文件路徑中的反斜杠替換為雙反斜杠,以便在 dir 命令中使用。8. for /f usebackq tokens=1-6 delims=/: %%c in ('dir /tc !file_path! ^| findstr /l /c:<') do ( - 獲取文件的創(chuàng)建時(shí)間,并將其轉(zhuǎn)換為 ISO
文本數(shù)據(jù)大小
防護(hù)金具 中航電測 櫻桃的功效與作用 茵陳的功效作用與主治 文安 微信拍一拍后綴 芯瑞達(dá) 中國礦業(yè) elasticsearch查詢語法去重復(fù) 制砂機(jī) 湖北生物科技職業(yè)學(xué)院 校服訂做資訊
批處理如何讀取txt文檔中的代碼并逐行執(zhí)行
2026-01-23
3種適合上班族用來刪除文件名中空白部分的辦法
2026-01-23
一個(gè)含金量超級高的SUMIF函數(shù),新手必須得會
2026-01-23
如何找出一個(gè)單元格是否在Excel中的其他單元格中被引用
2026-01-23
批處理怎樣在不同的文件夾里面獲取文件名列表
2026-01-23
word文檔怎么看多少字
2026-01-23
怎么樣將Word轉(zhuǎn)為PDF -PDF轉(zhuǎn)換器
2026-01-23
如何批量將Word文檔轉(zhuǎn)為PDF格式
2026-01-23
word怎么換照片的底色
2026-01-23
將PPT文件按主題拆分成多個(gè)PPT文件
2026-01-23
分享不要在批處理for命令內(nèi)部定義標(biāo)簽
2026-01-23
在線Excel表格|excel在線|Excel在線表格
2026-01-23