ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Finished Programs

DONE: Removing zero length files recursively at command-line

(1/4) > >>

questorfla:
In the process of TRYING to use SharePoint I have ended up with a LOT of zero length  (0 kb) files scattered all over a folder that has a total of over 50k small files in it.  These have various names and most if not all may have a space in the filename.  You would think there would be a simple command-line argument to remove all files of zero length.  If there is I can't find it.  And what I did locate used the "find" command with some arguments that may no longer be valid. 

I just need a way to do the scanning and removing of these empty files in various sub-folders and sub-sub-folders of a "c:\Data" directory.
The variations on the Find command only return errors and some of the options may be invalid in newer Windows OS systems even at a command prompt.  have to run this on more than one system,  some running  Windows 7 some 8.1.


--- Code: Text ---find . -empty -type f -delete
as well as

--- Code: Text ---find . -type f -size 0 -delete
These examples are supposed to work but don't
Not only do I get a config error but I don't see any way for this to scan recursively when run from a command prompt inside the Data folder.
It might be a better idea to MOVE those Zero length files to a folder named "C:\Zero" instead of outright deletion.   Just in case.  Paranoia is a good thing some times. :-\

4wd:

--- Code: Text ---REM Del0Files.cmd@echo offfor /f "usebackq tokens=*" %%a in (`dir /os /b /s /a-d-s-h-l "%~1\*.*"`) do (if "%%~za"=="0" del "%%~a")
Call as:

Del0Files.cmd <path>

Change the:

del "%%~a"

to:

move "%%~a" "C:\Zero\%%~na"

if you want to move instead.

Here's a recursive commandline delete empty directory that I got from StackOverflow, (IIRC):


--- Code: Text ---rem Del0Dir.cmd <directory>@echo offfor /f "usebackq delims=" %%a in (`dir /ad /b /s "%~1" ^| sort /r`) do rd "%%~a" 2>NUL
For cleaning up the dirs after you delete all the files :)

Test it first, the rd should fail if the directory isn't empty thus skipping it.

questorfla:
OK then kick me now while I'm down :) but I cannot get this next on to follow the focus of the calls.
Simple, easy, and worked perfect but created my folder it root C.
trying to automate a few things that I have pieced together most of on DC over time.
Using Clavier+ I set alt+F5 to run a batch file named auto.bat that was supposed to allow me to input a few characters which should be used to create a folder at the location where my prompt is when I run the Al+F5.   I knew it wasn't going to work but still not sure how to get the file to be created where I run the hotkey.
It could be inside of any one of 30 different root folders.  It then copies the contents of a generic starter setup with al the necessary parts and pieces waiting to be customized for that user.
While it did "Thankfully"! :o create the subfolder properly before dumping about 1000 misc. files all over the place, it did so at root C:
I have only looked for 15 minutes trying to find the (probably simple) method to get the focus of the command to be inside the folder I am in when I run the hotkey, I can't find anything that appears to work that way.  I cannot write the path into the batch as I will be using it in various places every time I call with ALT=-F5.   :-\  I just had a better idea to save room, if I could unzip a zipped copy of all the required stuff that would probably be even better.
Once this part is working, I have to use the same name to create a MySQL Database from a command line.  This something I had help getting to work a while back  have to see who to thank for that one.  Once I put it all together, I should be able to use a single hot key to setup the whole thing.

Only thing let is finding the best image utility to resize an image to a specific size (in pixels) png file with as little loss as possible,  So far, PAINT has been doing a pretty good job since I may have to start out with a jpg or whatever they send me.  I found a few Online utilities but prefer to work with all programs and files "in hand"  I'm just tossing this out to see if anyone has a favorite that I have not yet tried.  Most of them that are any good are far too complicated.  I just need to take a 380x260 (or ?) pixel jpg photo and change it to a 742x350pixel png file and not lose so much resolution  cant ell what it was to start with.   :D  I usually end up looking for a similar but larger one I can shrink instead.

4wd:
OK, from here:

OK then kick me now while I'm down :) but I cannot get this next on to follow the focus of the calls.-questorfla (July 31, 2014, 11:41 AM)
--- End quote ---

to here:

Once I put it all together, I should be able to use a single hot key to setup the whole thing.
--- End quote ---

I'm going to sum up with  :huh:

I just need to take a 380x260 (or ?) pixel jpg photo and change it to a 742x350pixel png file and not lose so much resolution  cant ell what it was to start with.   :D  I usually end up looking for a similar but larger one I can shrink instead.
--- End quote ---

SmillaEnlarger v0.8.0 - last Windows version

questorfla:
yep.  I feel just like that too,  And I am supposed to know at least what I am trying to ask.  Woke up with what I THINK may be the only adult onset case of Pinkeye I know of.  Had to get some killer drops for my eyes and some other stuff that between the two I cant see what I am even typing.

When you use "set" in a batch file to allow input for the data stored in a variable like "set %name% subdirectory"
I see the word subdirectory and enter the characters I want to use    like "nextone".
then use that to create the subdirectory with the next line md %name%

At the time I am calling this batch, I am already in the place I want to create the subdirectory.  This location varies and so do the name and the path to get where I would be is too long to have to type in the whole thing.  My "plan" was for this batch file to create the sudbir using the entered name right there where I called it from.
I linked the batch file itself to be run when I press AltF5 as a hotkey sequences .  Everything works fine except the subdir gets created under top level c:\ instead of Way down the path where I am running it from.
So .  I tried using "%~dp0" but that was a no go as well.

It could be that because I located the batchfile (I just called it auto.bat) in c:\ so I would be in the default path no matter where I was when I pressed AltF5 that maybe I am stuck.  I was hoping it would use the location of my "cursor" a a reference point and create the subdirectory there.

and thanks for the "enlarger"  I have never seen that one!   :Thmbsup:
Speaking of SEE.  I can see a bit better now :)

Navigation

[0] Message Index

[#] Next page

Go to full version