topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday April 19, 2024, 9:09 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Idea: File Resizer  (Read 5669 times)

Ordstrin

  • Member
  • Joined in 2009
  • **
  • Posts: 32
    • View Profile
    • Ordstrin's Home
    • Donate to Member
Idea: File Resizer
« on: August 23, 2009, 10:08 AM »
This is, I'll admit, an odd request.

I'd like a program that can resize a file to 0 bytes without deleting it or touching the file name.
A batch mode would also be exceedingly welcome.

The basic procedure I currently use (when I need to) is:
1) Open notepad.exe
2) drag & drop the file onto notepad
3) Select all & delete
4) Save changes

I'd love a program that can do this for me automaticallly though.
Yes I know there are much more efficient ways of going about this but...

Time for bed now, my peculiarities demand sleep also.

~Ordstrin

EDIT:

A few more requirements to go with this odd request.

a) The other files in the directory shouldn't be touched.
b) It should work on all file types (including executables).
c) I'm currently running a Windows system.
« Last Edit: August 24, 2009, 01:45 AM by Ordstrin »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Idea: File Resizer
« Reply #1 on: August 23, 2009, 05:33 PM »
Just create a batch file in a folder in your Path.  In my case I named it zero.cmd.

@echo off
type nul > "%1"

To "zero" all .txt files in the current folder you can use a command prompt:

for %s in (*.txt) do zero %s

or you can make a .cmd file that uses shift to go through the command line args.
Linux shell stuff is generally better about command line globbing than Windows though.

You could probably do it with gnu win32 utilities using find.

scancode

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 641
  • I will eat Cody someday.
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Idea: File Resizer
« Reply #2 on: August 23, 2009, 05:40 PM »
Just create a batch file in a folder in your Path.  In my case I named it zero.cmd.

@echo off
type nul > "%1"

To "zero" all .txt files in the current folder you can use a command prompt:

for %s in (*.txt) do zero %s

or you can make a .cmd file that uses shift to go through the command line args.

for %s in (*.txt) do @nothing 1>%s 2>nul
The same, but doesn't require a second cmd file :)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Idea: File Resizer
« Reply #3 on: August 23, 2009, 08:00 PM »
Or do

for %s in (*.txt) do type nul > %s

and have no .cmd file at all.  That's how I'd do it if I was using command prompts.  In AutoIt3 or some other language that does easy Guis with drop targets just drag & drop and call a file write function to zero the files in the drop list.  Depends if you're primarily interested in batch... but the drop target gui, if the window is created dynamically, can just pass on creating the window if you have command line params for the files, and be dual purpose.


It's pretty trivial.

scancode

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 641
  • I will eat Cody someday.
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Idea: File Resizer
« Reply #4 on: August 23, 2009, 08:06 PM »
Or do

for %s in (*.txt) do type nul > %s

and have no .cmd file at all.

Mine didn't require a .cmd file either, but yours is a lot cleaner! Added to snippets list :Thmbsup:

Ordstrin

  • Member
  • Joined in 2009
  • **
  • Posts: 32
    • View Profile
    • Ordstrin's Home
    • Donate to Member
Re: Idea: File Resizer
« Reply #5 on: August 24, 2009, 01:44 AM »
Ahh... the.... negative benefits of posting late at night.
A few clarification points before I go continue being preoccupied.
I'll edit the previous post with them too.

a) The other files in the directory shouldn't be touched.
b) It should work on all file types (including executables).
c) I'm currently running a Windows system.

I shall return later to read the previous comments (I did a skim read so far, which will have to do for now, kinda busy).

~Ordstrin

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Idea: File Resizer
« Reply #6 on: August 24, 2009, 03:43 PM »
Or do

for %s in (*.txt) do type nul > %s

and have no .cmd file at all.

Mine didn't require a .cmd file either, but yours is a lot cleaner! Added to snippets list :Thmbsup:

I was just luckier at google that's all. :)

The command prompt tricks section of my brain is rusty.  I should have thought of command line redirection myself, but I just googled "zero length files"!!  I know, it's cheating. :)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Idea: File Resizer
« Reply #7 on: August 24, 2009, 03:48 PM »
Ordstrin the "*.txt" was just an example.  The command line "type nul > filename" will zero any file named "filename".  It just overwrites the file from 'nul' which has no content, then closes the file.

You just need to decide how to substitute for "filename" with a replaceable parameter.  If your main interest is using it in batch then I would read up on subcommands and keywords used in NT style .cmd files(that use cmd.exe.)  There are plenty of sources on the web.