I would like to rename a directory using wild card

Posted on 2011-05-04
Last Modified: 2012-05-11
I manage about 5000 Windows PCs and because our PR department insists on including graphic files in our outlook email signature, the outlook cache file gets full and the end users start seeing red x in place of the graphic. This is a known issue and the resolution is to empty the folder. On a windows xp machine, that directory is located at %userprofile%\local settings\temporary internet files\olkXXX where X is a random alpha/numeric. On a windows 7 box the directory is located at %userprofile\appdata\local\microsoft\windows\temporary internet files\olkXXX

What I thought I wanted to do is create batch or script that can be run via SCCM or at the least via a call from logon.bat that will del the contents of that directory at user logon. I have tried just doing a simple del command in batch and have had some limited success but because of some variables in our deployment I have reached the conclusion that what I really want to do is just delete the directory because Outlook will create a new one as needed. However, because the directory name will be different on every computer and in fact, different for every user on any given computer, it is somewhat problematic to identify the name via a batch.

I have some old experience with the command line but it has been some years and I think PushD and PopD may be useful but would like to hear from anyone that has already solved this problem.

Edited for more clerity.


Question by:G094389
    LVL 6

    Accepted Solution

    Should be easy. Tested this on mine and it works. Make it a .bat file and it should do the trick.
    PushD %userprofile%\appdata\local\microsoft\windows\temporary internet files
    For /f %%j in ('Dir /B /AD test*') Do (
    RD /S /Q %userprofile%\appdata\local\microsoft\windows\temporary internet files\olk%%j)

    Open in new window


    Author Comment

    Tested, appended a pause at the end, ran as .bat and got the following return:

    D:\install>PushD C:\Documents and Settings\z987281\appdata\local\microsoft\windows\temporary internet files
    The system cannot find the path specified.

    D:\install>For /F %j in ('Dir /B /AD test*') Do (RD /S /Q C:\Documents and Settings\z987281\appdata\local\microsoft\windows\temporary internet files\olk%j )
    File Not Found


    Press any key to continue . . .

    I suspect it might have something to do with the spaces in the path. Researching that but if you have a suggestion, thanks in advance. I believe you are giving me what I'm looking for here.

    Author Closing Comment

    Ran it first on my XP test machine. Wasn't paying attention. Ran it again on a Win 7 box. Success. And thank you.
    LVL 6

    Expert Comment

    I ran mine under temp instead of temprary internet files due to me not wanting to actually delete my file.

    I will add the quotes, but I also remembered I did not account for the different path names in XP and Win7. I know %appdata% gets you to the app data folder in 7. Let me check where it goes in XP and see if i can modify it accordingly. Worse case, you can put both paths, and one will fail on each computer, the XP or 7.
    LVL 6

    Expert Comment

    Thats good. After checking, %appdata% takes you to the C:\users\username\appdata folder in WIndows 7. And to the Application Data folder in windows XP, so that change wouldnt help your script anyway.

    Author Comment

    Below is the final batch I'm going to test. This is for anyone else that is interested.

    Thanks again CrowaX

    @Echo off
    If Not Exist "%userprofile%\appdata\local\microsoft\windows\temporary internet files" goto XP
    PushD %userprofile%\appdata\local\microsoft\windows\temporary internet files
    For /f %%j in ('Dir /B /AD olk*') Do (
    RD /S /Q "%userprofile%\appdata\local\microsoft\windows\temporary internet files\%%j")
    goto finished
    PushD %userprofile%\local settings\temporary internet files\
    For /f %%j in ('Dir /B /AD OLK*') Do (
    RD /S /Q "%userprofile%\local settings\temporary internet files\%%j")

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
    The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now