Windows Vista Forums

Making simple bat files

  1. #1
    ilikefree's Avatar

    Senior Member



    Join Date : Jan 2010
    New Zealand
    Posts : 2,545
    Vista Home Premium 32bit.SP2
    Local Time: 12:22 AM
    newzealand

    Making simple bat files

    Could some knowledgeable person please tell me how to make a simple program that would be run once to delete all the smut off my computer (in 2 folders) when it is run.
    The reason is I want to leave this computer to someone and make it so they can delete folders without having to look for them.
    Don't want to shock my sister too much.
    I thought of a bat file but don't know enough about them @Echo% etc.
    I have looked at some sites that give examples of bat files but don't explain what all the symbols mean and how to use them.
    I like the idea of writing it in Notebook as no other programs are needed.

      My System SpecsSystem Spec

  2.   


  3. #2



    Banned

    Join Date : Dec 2009
    Posts : 3,375
    Vista Home Premium x86 SP2
    Local Time: 01:22 PM
    uk european union

     

    Re: Making simple bat files

    Hello,

    I will write it for you and explain it if you tell me exactly what you want it to do

    Richard

      My System SpecsSystem Spec

  4. #3
    ilikefree's Avatar

    Senior Member



    Join Date : Jan 2010
    New Zealand
    Posts : 2,545
    Vista Home Premium 32bit.SP2
    Local Time: 12:22 AM
    newzealand

      Thread Starter

    Re: Making simple bat files

    Thanks very much for the offer I have PM you to tell you what I need.Ta

      My System SpecsSystem Spec

  5. #4
    pacinitaly's Avatar

    HappyGuru Lovin2Help

    Join Date : Jan 2009
    worst state in America
    Posts : 1,396
    VISTA Business 32bit SP2
    Local Time: 08:22 AM
    usa

     

    Re: Making simple bat files

    how can i make this attached file open only 1 IE window and 14 tabs?

      My System SpecsSystem Spec

  6. #5



    Banned

    Join Date : Dec 2009
    Posts : 3,375
    Vista Home Premium x86 SP2
    Local Time: 01:22 PM
    uk european union

     

    Re: Making simple bat files

    Quote Originally Posted by pacinitaly View Post
    how can i make this attached file open only 1 IE window and 14 tabs?
    Hello,

    You will soon discover that Microsoft has not programmed this functionality, and it is not possible. There is only one solution, and it is very messy, and it is here: IE Automation & Tabs - Tony Schreiner's Blog - Site Home - MSDN Blogs

    Richard

      My System SpecsSystem Spec

  7. #6



    Banned

    Join Date : Dec 2009
    Posts : 3,375
    Vista Home Premium x86 SP2
    Local Time: 01:22 PM
    uk european union

     

    Re: Making simple bat files

    Hello,

    I have done it for you. Please be very careful, as this batch file is live, and "testing it out" will complete the operation you have asked me to get done for you, so be careful. I have properly tested it. I have included everything below. All you need to do is make a batch file with the extension of .bat, and save it anywhere. Right click on the batch file, and click Edit. Paste in the code below and save the notepad document. Now the batch file will work, so be careful. Files will not be sent to the recycle bin, but be immediately deleted.

    I have put in a safeguard "Press any key to begin:" and so if you do accidentally run it, immediately close it with the Red X and do not press any key, as you can start it with any key, not just enter.

    As you asked for, it will self destruct once it has completed and completion has been acknowledged. You may call it anything, as I have not hard coded to a particular name, just "whatever name it runs under, i.e. %0.

    I do not know how long it will take, it could take up to 20 minutes, or be instant, so I have explained both possibilities.

    If you want anything changed, or anything added, do not be afraid to ask.

    The Code:

    Code:
    @echo off
    echo Converting computer to new user...
    echo.
    echo NOTE: This operation may take up to 20 minutes. Please do not interrupt this 
    echo operation, or use the computer during this time. Do not worry if this operation
    echo takes a much shorter time, this is fine.
    echo.
    echo Press any key to begin:
    pause > nul
    echo.
    echo Working...
    echo.
    rmdir /s /q C:\Users\username\Videos\R18\ > nul
    rmdir /s /q C:\Users\username\Pictures\"Slide Shows"\ > nul
    echo Finished!
    echo.
    pause
    del %0
    How it works (line by line):


    • @ echo off: Switch off display commands on screen, only display what I ask it to display.
    • All of the echos are just comments, lines that go off the edge of the screen need to be brought into two lines manually, otherwise word is half on each line.
    • echo. Displayed a blank line.
    • pause > nul accepts any key, but the > nul does not display the prompt so I can put in my own prompt above as an echo comment
    • rmdir removed specified directory (/s removes all subdirectories, files, and directory itself), (/q to suppress prompt) and double quotes ("") to cope with folder name with space in it. The > nul does not display what it is doing.
    • pause asks for confirmation of completion, with default message.
    • del 0% deletes the batch file and %0 is a variable with name of running batch file, so deletes itself no matter what it is called.
    If you want any changes, just ask, I am more than happy to help you and make changes. Make sure the directories are correct, and so please read all of the code and make sure you are happy with the comments and functionality.

    Richard

      My System SpecsSystem Spec

  8. #7
    ilikefree's Avatar

    Senior Member



    Join Date : Jan 2010
    New Zealand
    Posts : 2,545
    Vista Home Premium 32bit.SP2
    Local Time: 12:22 AM
    newzealand

      Thread Starter

    Re: Making simple bat files

    Thanks for that I have saved it as a txt file for now and will change it to a .bat later. I have told my sister how to use it to save her blushes.

      My System SpecsSystem Spec

  9. #8



    Banned

    Join Date : Dec 2009
    Posts : 3,375
    Vista Home Premium x86 SP2
    Local Time: 01:22 PM
    uk european union

     

    Re: Making simple bat files

    You are most welcome!

      My System SpecsSystem Spec

  10. #9
    MilesAhead's Avatar

    Eclectician



    Join Date : Jan 2008
    Posts : 2,300
    Vista Home Premium 64 bit SP1
    Local Time: 08:22 AM
    usa

     

    Re: Making simple bat files

    Quote Originally Posted by ilikefree View Post
    Thanks for that I have saved it as a txt file for now and will change it to a .bat later. I have told my sister how to use it to save her blushes.
    Another approach, if I understand the goal correctly, you can just add the contents of folders you want deleted to CCleaner using Options Include.

    Comes in handy for stuff like a browser that's not in the cookies cleaner list, or if you want to clean out the cache etc..

    If you want to delete the contents of a folder but not the folder itself just use *.* at the end as in:
    c:\folder\*.*


    edit: just another way to skin the cat. I was clearing my Chrome cache using the CCleaner method but I found I was killing it too frequently, so I made a separate .cmd batch file to clear the cache when I think of it:

    Code:
    @echo off
    set /p ConfirmVar=Enter Y to Clear Chrome Cache.. 
    If %ConfirmVar%==y goto doit
    If %ConfirmVar%==Y goto doit
    echo Chrome Cache Clear aborted
    goto end
    :doit
    del "C:\Users\Owner\AppData\Local\Google\Chrome\User Data\Default\Cache\*.*"
    :end
    It's a bit sloppy in that you get 2 confirmation prompts but at least it lets me know it's going to delete the cache. The thing I learned new in this is the "set /p" command for getting user input and assigning it to a variable. I think it's new to Vista/W7.

    edit2: btw if you are new to batch files, a good idea is to make a folder and add it to the Path to chuck batch and single .exe files in that don't have any configuration. That way you can open a command prompt and not worry about the default directory. It will find the batch file.

    I use C:\Utils and put all kinds of portable apps and batch files in there. If I should do a Custom Windows install, it doesn't get swept up into Windows.old. Usually you just need to make a shortcut to use the programs right away since there's no registry settings. If the program has subfolders or .ini file or whatever, I make a folder and shortcut for it under C:\Utils. After a custom install all my stupid little hotkey tray apps are still there. No reinstall.

      My System SpecsSystem Spec

  11. #10
    ilikefree's Avatar

    Senior Member



    Join Date : Jan 2010
    New Zealand
    Posts : 2,545
    Vista Home Premium 32bit.SP2
    Local Time: 12:22 AM
    newzealand

      Thread Starter

    Re: Making simple bat files

    Yeah thanks MilesAhead I only have 2 folders I need her to be able to delete without her looking for them. All sorted now thanks. Niemiro has kindly done that and saved me the trouble of having to learn how to do it.I have Hodgkin's and don't have a lot of time left to learn too much in the way of new stuff.Thanks for the instructions though others will find it useful.

      My System SpecsSystem Spec

Page 1 of 2 12 LastLast

Making simple bat files
Similar Threads
Thread Forum
Re: Comparing two files and making changes PowerShell
Making a .vfd form a directory of files............. Virtual PC
Making a files always opne as administrator Vista security
Making CDs of system files (Vista)...? Vista installation & setup
WPF: making simple things easy and difficult things impossible? (Rant) Avalon