# Solved: batch programming question - getting filename to variable



## sternkanz

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

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


----------

