| 1. |
Solve : Batch file with dynamic file name? |
|
Answer» I'd like to have a shortcut/batch file on my desktop that will open a file which changes name somewhat each time it is updated. I'm not even sure if this is POSSIBLE, but here's the situation. hm, well i'm still learning so theres probably an easier way, but heres what i have. I tried this (after creating a sample text file called 'log"): @echo off for /f "tokens=1" %%a in ('dir /b /o:d c:\Users\Desktop\Chris Cione\log.txt') do set file=%%a notepad.exe %file% When I ran the batch, I got the message "The system cannot find the path specified." I know that's the path because I checked the file properties. Is there SOMETHING I need to modify in the code? Here you go, it should handle spaces now. Code: [Select]@echo off for /f "tokens=1" %%a in ('dir /b /o:d "c:\path\of\file\"') do set file=%%a start notepad "%file%"Quote from: Dusty on August 08, 2009, 07:38:11 PM Chris - Welcome to the CH forums.I used this: @echo off for /f "tokens=1" %%a in ('dir /b /o:d "c:\Users\Chris Cione\Desktop\log*"') do set file=%%a start notepad "%file%" I have two files I created for testing purposes - "log 080109" and "log 080509". The code won't open either; I'm prompted to create a new file called "log". What I'm attempting is to create logic so that the batch searches for the most current file (by date) and open that file. well this is all i got left, kinda sloppy because it wont handle double spaces.... Code: [Select]for /f "tokens=1-4 delims= " %%a in ('dir /b /w /o:d "c:\tests\"') do set file=%%a %%b notepad.exe %file%Quote Tried it. A DOS window briefly (very briefly) open and closes. Nothing else happens. Sorry about that. I have tested this ONE and it works on my Win 2k when opened in Explorer, from a desktop shortcut and from the command line. Please INSERT your path to the files in the Pushd command line. Code: [Select]@Echo Off setlocal cls pushd "path\to\files\" for /f "delims=*" %%# in ('dir /tw /o-d /b "status log *"') do ( start notepad %%#& exit ) |
|