You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用批处理脚本从文本文件批量创建带日期命名的URL快捷方式

Solution: Create Date-Named .URL Shortcuts from a Text File of URLs

Let's fix your batch script to extract the start_date from each URL, reformat it, and use it as the shortcut filename. Here's a complete, tested solution that addresses all your pain points:

Complete Batch Script

@Echo Off
SetLocal EnableDelayedExpansion
CLS

REM --- Configuration (Update these paths to match your setup!) ---
Set "URL_FILE=C:\Users\UserName\OneDrive\Desktop\Report Creation\FileNameOfURLS.txt"
Set "SAVE_DIR=C:\Users\UserName\OneDrive\Desktop\Report Creation\All URLS Here"
Set "SHORTCUT_SUFFIX= mileage report"
REM ---------------------------------------------------------------

REM Create the save directory if it doesn't already exist
If Not Exist "%SAVE_DIR%" MD "%SAVE_DIR%"

REM Process each URL line in the input text file
for /F "tokens=* delims=" %%A in ('Type "%URL_FILE%" ^| Find /V ""') do (
    REM Step 1: Extract the raw start_date value from the URL
    Set "URL=%%A"
    Set "DATE_PART=!URL:*start_date=!"  &REM Remove everything before "start_date"
    For /F "tokens=1 delims=;" %%B in ("!DATE_PART!") do Set "RAW_DATE=%%B"  &REM Grab everything before the next ";"
    
    REM Step 2: Convert YYYY-mm-DD to mm-DD-YYYY format
    For /F "tokens=1,2,3 delims=-" %%C in ("!RAW_DATE!") do (
        Set "FORMATTED_DATE=%%D-%%E-%%C"  &REM Swap year with month/day
    )
    
    REM Step 3: Create the .URL shortcut file
    Set "SHORTCUT_NAME=!FORMATTED_DATE!!SHORTCUT_SUFFIX!.URL"
    Echo [InternetShortcut] > "%SAVE_DIR%\!SHORTCUT_NAME!"
    Echo URL=%%A >> "%SAVE_DIR%\!SHORTCUT_NAME!"
    Echo IconFile=C:\Program Files\Google\Chrome\Application\chrome.exe >> "%SAVE_DIR%\!SHORTCUT_NAME!"
    Echo IconIndex=0 >> "%SAVE_DIR%\!SHORTCUT_NAME!"
    
    REM Optional: Print progress to the console
    Echo Created shortcut: !SHORTCUT_NAME!
)

Echo.
Echo All shortcuts created successfully!
Pause
Exit /B

How This Solves Your Problems

1. Batch For Loop & Special Character Handling

  • SetLocal EnableDelayedExpansion: This fixes variable substitution issues inside loops (critical when working with dynamic values like URLs and dates).
  • for /F "tokens=* delims=": Ensures we read the entire line of the URL, even if it contains spaces or special characters.
  • Type "%URL_FILE%" ^| Find /V "": Skips any empty lines in your URL text file to avoid errors.

2. Extracting the Date from Variable-Length URLs

  • Set "DATE_PART=!URL:*start_date=!": Uses batch's string substitution to strip off everything in the URL before the start_date keyword.
  • The second for /F command splits the remaining text at the ; character, grabbing just the YYYY-mm-DD value we need.

3. Converting Date Format

  • The final for /F command splits the raw date by - into three parts: year (%%C), month (%%D), day (%%E). We then reorder these to create the mm-DD-YYYY format you need.

How to Use

  1. Copy the script into Notepad.
  2. Update the URL_FILE and SAVE_DIR paths to match your actual file locations.
  3. Save the file as CreateReportShortcuts.bat (make sure "Save as type" is set to "All Files").
  4. Double-click the batch file to run it – your .URL shortcuts will appear in the specified directory!

内容的提问来源于stack exchange,提问作者TruckDriverOnPC

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 16:15:57