| 1. |
Solve : Why Doesn't This Batch File Work?? |
|
Answer» Hi everyone, Look at the for /r command, I believe this is what you are looking for. I'm not very well versed in it's uses, so I can't write you one off the top of my head. It's ok, I appreciate your help. Maybe someone else knows and can help me out with this one.If no one else replies when I get back on tomorrow I'll start running some tests and see if I can get it for you. Good luck though.Batch math fails above a number around 2 GB. An accurate DESCRIPTION of the file size limits would help to provide something that works. This question has been multiposted: http://stackoverflow.com/questions/26695993/final-step-of-batch-file-doesnt-work-why http://stackoverflow.com/questions/26689398/batch-file-commands-to-keep-smallest-directory-and-delete-all-others Quote from: foxidrive on November 02, 2014, 12:34:30 AM Batch math fails above a number around 2 GB. Yes, I had posted this question elsewhere. The original problem I had has been resolved. The only thing I need to figure out is what I asked in post #3 of this thread. The sizes of the directories are not over 2GB. Comparing the sizes and deleting the smallest directories (DIRA, DIRB, DIRC, etc.) is what I am trying to achieve. Comparing the sizes and deleting the smallest directories (DIR1, DIR2, DIR3, etc.) which are in the same folder as the batch file is NOT what I want to achieve but that is what the batch file does now in the way that it's written.Remove the echo keyword after testing - at present it will echo the RD commands to the console. Code: [Select] echo off :: keeps only the smallest folder, deletes all the largest folders, in all the next level folders below this folder setlocal EnableDelayedExpansion for /d %%a in (*) do ( (for /d %%b in ("%%a\*") do ( for /f "tokens=3" %%c in ('dir "%%b" /s /-c ^|find "File(s)" ') do set "size=000000000000000%%c" echo !size:~-15! "%%b" ) )>"%temp%\checksize.bin" sort <"%temp%\checksize.bin" >"%temp%\checksize2.bin" for /f "usebackq skip=1 tokens=1,*" %%d in ( "%temp%\checksize2.bin") do echo rd /s /q "%%~e" del "%temp%\checksize?.bin" ) pause Quote from: foxidrive on November 02, 2014, 02:58:11 AM Remove the echo keyword after testing - at present it will echo the RD commands to the console. Created a new batch file with your code. When executed, the result is line after line of this: Code: [Select]'find' is not recognized as an internal or external command, operable program or batch file.Your Windows seems broken for some reason. A likely reason is when someone uses the PATH variable for some other use, or the path variable has been edited in the Windows GUI and parts removed. Quote from: gmgdr11 on November 02, 2014, 06:13:38 AM Created a new batch file with your code. When executed, the result is line after line of this: Do you have a variable called %path% in your script? Quote from: Salmon Trout on November 02, 2014, 06:30:08 AM Do you have a variable called %path% in your script? Well no. What I did to test that and generate that error was to copy the code in the post into a blank Notepad window, save it as "test.bat" in root folder of DIR1, DIR2, DIR3 and executed. I apologize for my very basic knowledge of batch file writing. Programming, even at the most basic level, is something I am not very familiar with. Quote from: gmgdr11 on November 02, 2014, 06:42:47 AM Well no. What I did to test that and generate that error was to copy the code in the post into a blank Notepad window, save it as "test.bat" in root folder of DIR1, DIR2, DIR3 and executed. Open a cmd window and type find /? and sort /? See if they both give you help. Quote from: foxidrive on November 02, 2014, 07:01:36 AM Open a cmd window and type find /? and sort /? Ok! Fixed it. The issue was that I had the PATH environment variable set to C:\Cygwin64\. It displays the correct folders to be deleted. I get the following: Code: [Select]rd /s /q "DIR1\DIRA" rd /s /q "DIR1\DIRC" rd /s /q "DIR2\DIRG" rd /s /q "DIR2\DIRF" rd /s /q "DIR2\DIRE" rd /s /q "DIR3\DIRH" How does the batch file need to be modified then to execute those commands rather than display them now that it is confirmed that it accurately finds the proper directories to delete? Thanks. |
|