1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

Need help with batch file

Discussion in 'Windows XP' started by DugE, 2004/02/13.

Thread Status:
Not open for further replies.
  1. 2004/02/14
    Hugh Jarss

    Hugh Jarss Inactive

    Joined:
    2002/07/22
    Messages:
    908
    Likes Received:
    6
    aha - at last I've found an example of when the 8.3 thing goes wrong (having something other than ~1 at the end might be throwing you)

    look at Stephanie's folder here it's abbreviated to STEPHA~2 instead. I don't know why. Maybe there was once a STEPHA~1 and then it got deleted...

    I checked this with Microsoft pdf which said that the behaviour is undefined

    You can check this (ie what number is on the end of the 8.3 short name) by doing a dir - either from inside a BATch file or just straight at the DOS prompt, it doesn't really matter, whichever's easier.

    Start small and work up, if you hit an error message STOP! and let us know what it is

    Do you actually want to delete the index.dat file anyway?

    I always get worried about clearing out cookies with DOS like this - never quite sure if just deleting the cookies without letting the index.dat "catch up" is a good idea. Probably someone will know the answer!

    let us know how you are doing, and best wishes, HJ

    Other things you can Log Off...
    Forest
    Woodpile
    Lumberjack
    The Starship Enterprise
     
    Last edited: 2004/02/14
  2. 2004/02/15
    DugE

    DugE Well-Known Member Thread Starter

    Joined:
    2002/09/10
    Messages:
    726
    Likes Received:
    3
    Hi Hugh.

    I did a DIR of C:\Documents and Settings\Dopey. I then opened the folder I DIRed and compared. DIR showed 7 folders and 2 files. The folder itself has 15 folders and 3 files.

    All but one of the folders that DIR didn't show are Hidden. The one unhidden folder that DIR doesn't show is the Cookies folder.
    I have Windows set to show all files but am at a loss as to why these folders don't show in DIR.

    I haven't recieved any error messages yet. As soon as I click the batch file to run the command prompt appears for half a second then disappears. I've rewritten the batch file several times and the results are the same. If I do get an error message the command prompt doesn't stay active long enough for me to see it.

    The folders that are not listed in DIR are:
    Application Data
    Cookies
    Local Settings
    My Recent Documents
    Nethood
    Printhood
    Sendto
    Templates


    So I guess this is why my batch file don't work. It can't find the folders I want to empty. Any suggestions? Thanks.
     

  3. to hide this advert.

  4. 2004/02/15
    Hugh Jarss

    Hugh Jarss Inactive

    Joined:
    2002/07/22
    Messages:
    908
    Likes Received:
    6
    Hi John

    you could try
    dir /a
    which should show the hidden folders

    sorry I should have thought of that

    BUT whether we can del the files or not will depend upon the attributes of the files themselves, not (I think) the attribs of te folder - unless ?the folder has the read-only attribute set?

    easiest to check this with Windows Explorer, look at the properties for the files.

    if you want to "put the brakes on" in the middle of a BAT try using
    pause
    which should give you the dreaded "Press any key to continue..." prompt.

    dir at a DOS prompt has its own rules, it doesn't follow Windows settings

    ==

    the cookies folder - unhidden but won't show: isn't this a system folder? if so should show up with the dir /a OK

    best wishes, HJ
     
    Last edited: 2004/02/15
  5. 2004/02/15
    markp62

    markp62 Geek Member Alumni

    Joined:
    2002/05/01
    Messages:
    4,012
    Likes Received:
    16
    If you do this command, you will get all the DIR switches listed in a text file for easier reference.
    dir /? > c:\dir.txt
    You'll find it at C:\.
    I am not sure if this works in XP, but if you go to this Key and Add or Modify this Value, you'll have another column in Window Explorer listing file and folder attributes.
    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
    "ShowAttribCol "=dword:00000001

    You'll need to modify the bat file to change the attributes of the folder.
     
  6. 2004/02/15
    DugE

    DugE Well-Known Member Thread Starter

    Joined:
    2002/09/10
    Messages:
    726
    Likes Received:
    3
    Hi Hugh.

    The dir /a showed all folders and files. Thanks.

    In Windows Explorer I checked the folders and found them to be set to read only. Is this normal for xp? I'll need to change the attributes before any files will be deleted from these folders right?
    And if I do change them will they stay changed or revert to default after a restart/shutdown?

    Or maybe it would be better to use Mark's example of:

    for %%f in (COOKIES HISTORY TEMP TEMPOR~1 MYRECE~1) do attrib -r -s -h -a C:\DOCUME~1\DEFAUL~1\LOCALS~1\%%f\*.*
    for %%f in (COOKIES HISTORY TEMP TEMPOR~1 MYRECE~1) do del C:\DOCUME~1\DEFAUL~1\LOCALS~1\%%f\*.*

    This way the batch file will change the attributes of each folder and then proceed to delete the files?

    Also, in your example of Steph's folder I noticed the ~2 but on mine they show dates instead. Maybe I was looking in the wrong folder but as of yet I can't find any of the 8.3 dos names.


    Hi Mark. I haven't tried your suggestions yet but just wanting to say thanks now in case I forget to later. :)
     
  7. 2004/02/15
    markp62

    markp62 Geek Member Alumni

    Joined:
    2002/05/01
    Messages:
    4,012
    Likes Received:
    16
    To change the attributes of the folders themselves, add this one.
    for %%f in (COOKIES HISTORY TEMP TEMPOR~1 MYRECE~1) do attrib -r -s -h -a C:\DOCUME~1\DEFAUL~1\LOCALS~1\%%f
    Note the only difference is that there is no \*.* at the end.
     
  8. 2004/02/15
    DugE

    DugE Well-Known Member Thread Starter

    Joined:
    2002/09/10
    Messages:
    726
    Likes Received:
    3
    Mark it worked. Yeah. :)

    @ECHO OFF
    for %%f in (HISTORY TEMP TEMPOR~1) do attrib -r -s -h -a C:\DOCUME~1\DOPEY\LOCALS~1\%%f
    for %%f in (HISTORY TEMP TEMPOR~1) do del C:\DOCUME~1\DOPEY\LOCALS~1\%%f\*.*
    EXIT


    The above is the batch file I ran. It sucessfully deleted the contents of the named folders. Finally.

    The only thing I didn't like was having to input a 'y' at each prompt before it would delete the files. What switch will I need to use to have the batch run without prompting? Thanks.
     
  9. 2004/02/15
    Hugh Jarss

    Hugh Jarss Inactive

    Joined:
    2002/07/22
    Messages:
    908
    Likes Received:
    6
    reading Newt's post earlier, it looks like the /q for "quiet mode "

    good luck, HJ.
     
  10. 2004/02/15
    DugE

    DugE Well-Known Member Thread Starter

    Joined:
    2002/09/10
    Messages:
    726
    Likes Received:
    3
    Yep that was it thanks. I'm going to call it a night. Tomorrow I'm gonna rewrite the batch now that I got one line working. Good tip on that one Hugh.

    In the meantime I need help with part 2 of my batch file. This part involves the cookies I want to keep. I'm thinking of making a temp folder (that the batch won't delete) and have the batch move the cookies I want to keep into the temp folder, let the batch delete all the files, then move the kept cookies back to the cookie folder.

    Not many cookies, such as the one for this site, homepage, few others. Keep the cookies to cut down on retyping user name and password.

    I've used cookie managers in the past but when the batch deleted the cookie folder the ones I want to keep got deleted so I'm thinking this will be my best move. I'm not familiar with the move command, its switches if any, or its structure so a little info will be appreciated, especially since xp is so much different than 98.

    Part 3 involves running the batch from autoexec.bat. Mark has already explained how to edit the auto file but do I need to keep the myfile.bat in a certain place or will the root of C: be ok?

    Thanks for all the help guys.
     
  11. 2004/02/15
    Newt

    Newt Inactive

    Joined:
    2002/01/07
    Messages:
    10,974
    Likes Received:
    2
    Dopey - since XP does not run autoexec.bat at startup, I'm a little confused about exactly what you are planning to do.

    Also, if you force cmd.exe to run a bat file rather than using command.com you can use long file names just fine. cmd.exe is a full 32bit app and understands them fine. command.com is old 16bit code (not even as smart as the version in 9x/me) and does not.
     
  12. 2004/02/16
    markp62

    markp62 Geek Member Alumni

    Joined:
    2002/05/01
    Messages:
    4,012
    Likes Received:
    16
    You can put it at C:\, or any folder that is part of the PATH for convenience, so it can be found with just it's name. Enter in set at the prompt, and you will see the PATH spelled out for you.
     
  13. 2004/02/16
    Hugh Jarss

    Hugh Jarss Inactive

    Joined:
    2002/07/22
    Messages:
    908
    Likes Received:
    6
    John

    to find out what switches there are and roughly what they do, use /? for example
    move /?
    is how you get to a screen similar to Newt's post earlier up the thread

    If you run Mozilla it may get upset if you remove the cookies "manually" - at least that's what mine (1.2.1) says...
    ...thinks: maybe that's what stopped it working :confused:

    good luck, HJ.
     
  14. 2004/02/16
    DugE

    DugE Well-Known Member Thread Starter

    Joined:
    2002/09/10
    Messages:
    726
    Likes Received:
    3
    Newt - I'm confused too. I did not know that xp doesn't run an autoexec.bat at startup. I'm wanting to run the bat file at startup so I'll just put it in the startup folder and run it that way.

    Also I didn't know cmd.exe was different than command.com. I thought they were the same so explaining what I need to do to force cmd.exe to run the batch will help a lot here. Thanks.

    Mark - Yep, that worked, thanks.

    Hugh - Hmm I gather then that I can use the /? switch with all the dos commands to find info. I should've known that but my hardheadedness gets in the way most of the time. :) Thanks.

    When moving more than one file do I need to seperate each file with a comma or just use a space? For example:

    move C:\DOCUME~1\DOPEY\COOKIES\cookie1,cookie2,cookie3 C:\DOCUME~1\DOPEY\TEMP

    Thanks.
     
  15. 2004/02/16
    Newt

    Newt Inactive

    Joined:
    2002/01/07
    Messages:
    10,974
    Likes Received:
    2
    dopey - M$ was nice to us and the top of the window will clearly state if it is command.com or cmd.exe that is running. Just stick a pause statement in your .bat file so you can see what is happening before it exits.

    Not sure if you are going to have success with running the thing from your startup folder though. I think some items you want to dump may be protected by the time the system has the GUI loaded. Worth a try but don't be surprised if it does not work completely. I think the little .dat index files are pretty well protected. Other things should go away for you though.

    If you are ever working with an app that needs settings done by autoexec, the version that NT systems (NT4/2K/XP/2003) use is autoexec.nt but it is purely a thing that can be called when the app is started.

    Non-XP systems started DOS and loaded the Windows GUI as a global app on top of DOS but autoexec.bat and config.sys would run first, before the GUI Windows was loaded. NT systems do not run over DOS but are full operating systems.

    The more usual way to do this sort of thing in XP (pro version only though I think) is with startup/shutdown scripts. start~run~gpedit.msc should open a window with the scrip locations. This Technet article gives details on loading a shutdown script. You can have them for the PC or for an individual user.
    Some interesting and useful Scripts but none that do exactly what you want. May give you ideas for a starting place though. And This page includes a script for doing what you want with the trash cleanup. Written for 2K but after a read thru, I don't see any reason at all it won't do fine in XP-pro.

    There may be some interesting way to force a script to run on XP-home at shutdown or startup. I don't know of any but I don't use the Home version so never had a real reason to look around very much.
     
  16. 2004/02/16
    DugE

    DugE Well-Known Member Thread Starter

    Joined:
    2002/09/10
    Messages:
    726
    Likes Received:
    3
    Hi Newt -- I was also a little weary about running the batch from startup, with things getting installed and such it kinda seemed to me that running a batch here could cause some complications albeit minor. I'm not very familiar with xp, with what can and cannot be done with the limited dos. I'm no programmer but did some tinkering with batch files in 98. The scripts you linked to is somewhat over my head for the time being and I really don't have the "want to" to get into them.

    I did figure out how to get cmd.exe up and running but did no good with the way my batch was written so I'll have to change it. I'm not looking for anything complicated or sophistacated, just something simple that will do what I want, clean the temp folders and such so I wont have to go through and do it manually.

    When you mentioned earlier that cmd.exe can handle long file names did you mean that I could use 'Documents and Settings' instead of 'Docume~1'?

    If this won't run from startup I'll just click on the icon after windows loads and run it first before I do anything else. No big deal, I was just hoping to automate somewhat.

    Also, is there a way to get rid of the index.dat files? I'd like to delete them along with the files to keep things ballanced.

    Boy, the more I use xp the more I miss 98 although I have to admit xp is more stable and user friendly.
     
  17. 2004/02/16
    Newt

    Newt Inactive

    Joined:
    2002/01/07
    Messages:
    10,974
    Likes Received:
    2
    When you mentioned earlier that cmd.exe can handle long file names did you mean that I could use 'Documents and Settings' instead of 'Docume~1'?

    Yup. Sure did and you sure can.

    As far as I know, any batch file that will run under command.com should run under cmd.exe. Neither one will make use of apps or switches that don't exist with XP.

    For getting rid of the index thingys, I use a free app, Spider. Run it and then it will take care of the .dat critters during a reboot or after a shutdown and later restart.
     
  18. 2004/02/17
    DugE

    DugE Well-Known Member Thread Starter

    Joined:
    2002/09/10
    Messages:
    726
    Likes Received:
    3
    Thanks Newt. Now the fun begins. With several ways to do this I'm going to have to check them all out to see what will and will not run correctly. I'll check on Spider also. It just seems to me that if you're going to delete all the files you may as well delete the index.dat files also. Ballance the folder so to speak.

    Thanks also to everyone else. I ain't forgot. When I get something going that I like I'll post back and let everyone know how well things turned out. Also if I run into problems its good to know you fellows are here.

    I should be back tomorrow or Thurs at latest. Thanks again.
     
  19. 2004/02/19
    DugE

    DugE Well-Known Member Thread Starter

    Joined:
    2002/09/10
    Messages:
    726
    Likes Received:
    3
    No matter what I do I always come up with a file not found error. The first line in the batch runs well, the others are always file not found. I've tried using quotes, no quotes, uppercase, lowercase. Sheesh. I'll just do it manually. Takes about 8 minutes doing it manually and after two days of trying a batch I still have all my files.

    Thanks for the help though, it kept me busy these last two days.
     
  20. 2004/02/19
    Newt

    Newt Inactive

    Joined:
    2002/01/07
    Messages:
    10,974
    Likes Received:
    2
    dopey - have you tried (from either WE or My Computer)
    - locate a drive
    - right click on the drive icon
    - click on properties
    - click on 'disk cleanup'
    - go from there

    It only cleans for the currently logged on user but does a good job of that except for cookies.
     
Thread Status:
Not open for further replies.

Share This Page

  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.