Solved: batch programming question - getting filename to variable

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

sternkanz

Thread Starter
Joined
Oct 3, 2008
Messages
21
Hi, I want to create a batch program that I am going to run every 15 mins or so. What it does is check the folder for .pdf files, and if it finds one (its 99% guaranteed there will only ever be one) I want it to take the entire name of the file and put it into a variable.

e.g. Folder contains Script.bat and test.pdf

Script.bat gets executed, and within the script a variable is created which contains the value "test.pdf". I then do stuff with that variable, and finally use it to delete the pdf file.

It sounds fairly simple really, but I have no idea how to get the name of the file into a variable.

Any help very highly appreciated,
 

sternkanz

Thread Starter
Joined
Oct 3, 2008
Messages
21
Ok, so I figured that one out. I used this code:

for /F %%a in ('dir /b *.pdf') do set FileName=%%~na.pdf
del %FileName% /q
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top