1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: batch programming question - getting filename to variable

Discussion in 'Software Development' started by sternkanz, Oct 3, 2008.

Thread Status:
Not open for further replies.
  1. sternkanz

    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,
     
  2. sternkanz

    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
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/755758

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice