|
Answer» Now the fun starts!
I had a programming problem, with a XPCleanup batch file, where I wanted the program to do a starting count of the files on the C: drive, then remove the garbage files and then do another count and print out the difference. I received help with that problem, right here on this forum, for which I'm VERY thankful.
The program works as intended when I run it from within windows XP, but, when I run it from a boot disk that was formatted by Windows XP, the batch file crashes. First, on the initial count I get a Syntax Error and then as the cleanup portion of the batch file runs I get: del /F /S /Q Invalid Switch - /F
Most commonly, I'll be running this batch file from within windows, but I'd like the option to run it from a DOS Boot disk, like a CD or Flash Drive.
Here's a sample of the batch file in question:
Echo off cls Rem: Count the number of files on "C" before the cleanup. Echo: Performing initial file count. Please wait!
for /f "delims=" %%A in ( ' dir /a /s "C:\" ^| find /c /v "" ' ) do set Count1=%%A ::pause Echo: Disk Cleanup now starting. Please Wait! Echo off del /F /S /Q "C:\temp\*.*" >nul del /F /S /Q "%systemroot%\temp\*.*" >nul del /F /S /Q "%systemroot%\SYSTEM32\config\systemprofile\Local Settings\Temporary Internet Files\Content.IE5\*.*" >nul
del /F /S /Q "C:\Documents and Settings\NetworkService\Local Settings\Temp\*.*" >nul del /F /S /Q "C:\Documents and Settings\NetworkService\Local Settings\Temporary Internet Files\Content.IE5\*.*" >nul del /F /S /Q "C:\Documents and Settings\LocalService\Local Settings\History\History.IE5\*.*" >nul del /F /S /Q "C:\Documents and Settings\LocalService\Local Settings\Temporary Internet Files\Content.IE5\*.*" >nul del /F /S /Q "C:\Documents and Settings\LocalService\Local Settings\Temp\*.*" >nul
del /F /S /Q "C:\Documents and Settings\%Username%\Local Settings\Temporary Internet Files\Content.IE5\*.*" >nul
del /F /S /Q "C:\$Recycle.Bin.Bin\*.*" del /F /S /Q "C:\Recycled\*.*" Echo: Disk Cleanup is now complete. Rem: Show number of files left on HD after the cleanup. Echo: Performing File Count, After Cleaning. Please Wait!
for /f "delims=" %%A in ( ' dir /a /s "C:\" ^| find /c /v "" ' ) do set Count2=%%A
set /a deleted=%Count1% - %Count2% Echo: Echo: Echo File Count before cleaning: %Count1% files Echo: Echo File count after cleaning: %Count2% files Echo: Echo Files deleted: %deleted% files pause
If anyone knows how to fix this, would you PLEASE let me know.
Thank You, several problems:
1.the XP boot disk doesn't understand either the NTFS FILESYSTEM, so this will never work on a system whose hard disk is NTFS. 2.It Will only work on windows XP,2003 since those are the only windows systems that use C:\Documents and Settings\... more to the point, since that is a long name you might need to use the 8.3 filename for it from the boot disk, which you cannot guarantee to be the proper folder. 3. the Windows XP Boot disk is pretty much just DOS. Which explains issue 1 as well as the fact that del doesn't have the necessary switches. the only support switch with DEL from a boot disk would be /P to prompt before deleting. there is no /F or /S switch.
/F could be remedied by running a attrib and removing all attributes from files in the target directories. thankfully, attrib on the boot disk does support /S (which makes sense, it's available in DOS 6), then delete the files using DELTREE /Y, which you will have to copy yourself to the boot disk.
Another problem is that none of the control STRUCTURES will work, for doesn't support any of the functionality you are using it for, and set cannot do arithmetic in pure DOS.Let me see if I can respond to that, by the numbers. 1. my computer is all FAT-32, , there is NO NTFS. for NTFS drives, on customer's computers, I would run NTFS4DOS before I would run the batch file. That 'Allows' me to run batch files against the NTFS drive.
2. The name of the batch file is "XPClanup.bat". The key being "XP". This is NOT meant to be run on Vista or Windows 7. .....I'm writing a completely different batch file for those OS's.
3. I checked out DEL in dos and saw that the only switch is /P, not what I want to do. So, I use the syntax, " Echo y| del" to send a yes response to DEL each time it runs. I've done that before and it works just fine. I"ve been using Deltree /y in my batch files for many years now. It's just that I wanted to get away from having to load it wherever I want to run the batch file.
4. I have a way to get the COUNTS, before and after cleaning, but I couldn't figure out how to do the math. That's what originally brought me to this forum. I had everything down pat, except for that darned Math.
* Oh, by the way, long file names work just fine in DOS, as long as they are put inside of Quotes.
I may have actually run into a brick wall. There I said it! Looks like I'll be running my XPCleanup.bat program in Windows, so I can get a count of the files removed.
Shadow I'm going to show my naivity now...
Couldn't you use rd (or rmdir) in place of Deltree with it being an XP Cleanup disk? Or does that delete too much? Like I said, naive, but also wondering if an rd/md combo wouldn't end up leaving a cleaner end product.
Quote from: TheShadow on October 12, 2011, 08:04:29 PM * Oh, by the way, long file names work just fine in DOS, as long as they are put inside of Quotes.
Really? In MS-DOS? Name one version where you have made that work. Without an LFN driver.
Raven, That might work, but why would I change something I've been doing with 100% success, since before Windows.
I'm really kind of bummed out, that MS in their infinite wisdom would eighty six the Deltree.exe command.
I've heard it called the most powerful DOS command ever. It's power lies in the syntax in which it's used. It can delete just one file off of an entire HD, or it can delete a whole group of like files or an entire tree of files and folders or even wipe an entire HD. ( Deltree /Y C:\*.* ) With power comes danger and maybe that's why MS did away with the command. I still use it a lot for my own work.
I've been using long file names in DOS batch files for years, just by putting the path inside of Quotes. I'm hard pressed to even understand why anyone would doubt that. Eh?
At about 3AM this morning I finally figured out why my file counting line did not work from my DOS boot disk. The command line has the "Find" command (Find.exe) in it and that's an external DOS command that must also match, the version of the OS being used. (Command.com) So for the line to work at all, the Find.exe file has to be on the boot disk.
After finding and fixing that problem, I gave up and went back to bed. For now, I'm tabling the whole project. I have some other projects that are pressing me to complete them.
Thanks to some great help I got on this forum, my XPCleanup.bat program works great when run from within Windows, and the file counting routine now works too.
Thanks Guys!
Quote from: TheShadow on October 13, 2011, 11:51:56 AMI've been using long file names in DOS batch files for years, just by putting the path inside of Quotes. I'm hard pressed to even understand why anyone would doubt that. Eh?
Because MS-DOS filenames are limited to the 8.3 format? Eight characters for the filename and three for the extension?
http://en.wikipedia.org/wiki/8.3_filename
Of course, you might be one of those people who think (wrongly) that it is accurate to call all Windows command prompt environments "DOS". Which does call your self-awarded rating of "guru" into question.
Quote from: Raven19528 on October 13, 2011, 10:14:54 AMI'm going to show my naivity now...
Couldn't you use rd (or rmdir) in place of Deltree with it being an XP Cleanup disk? Or does that delete too much? Like I said, naive, but also wondering if an rd/md combo wouldn't end up leaving a cleaner end product.
The windows XP boot diskette is really just a Windows ME boot diskette, as VER will tell anybody booting from such a diskette. The DOS version itself is 7.2, I believe, (7.1 being the version that introduced support for FAT32). Either way, it still only has basic DOS command parsing ability (it splits at spaces, quotes are not a special character to it at all), and the internal commands are equally limited. rd and rmdir accept no switches. (this means you cannot use /s to delete a folder) and you can only remove an empty folder, so that wouldn't work.
Quote from: Salmon Trout on October 13, 2011, 10:50:53 AMReally? In MS-DOS? Name one version where you have made that work. Without an LFN driver.
Best not to ARGUE with an expert.
In any case, the run-down is this.
the for /f is never going to work. That would need to be changed.
There isn't really anything you can change it to in pure DOS batch. You might be able to get away with something involving find, but it is fairly limited pre-NT extensions as well. To be clear that entire for command is invalid syntax. there are no switches in plain DOS for the for command.
Another idea is that if you are creating a disc image or a USB drive for the purpose, you could use a Linux distro and set it to automatically run a shell script, which ought to be able to do any of the things necessary in the NT batch file. Also, it has "built-in" support for NTFS on any recent distro. Or you could try a WinPE environment, which should give you the NT command extensions your batch file needs.
As for long file names, as ST notes, it simply doesn't exist in pure DOS. the XP/ME boot disk doesn't read or consider VFAT entries, nor does it support the use of quoted names as one would CLAIM. This can be tested directly from a running XP machine by simply trying to use the the quoted form in the command.com interpreter (rather than cmd.exe) where it will issue 'Parameter format not correct - "C:\Documents"
Quote from: Salmon Trout on October 13, 2011, 12:00:37 PMWhich does call your self-awarded rating of "guru" into question.
I'm a proud Beginner!
|