topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Thursday March 28, 2024, 8:55 am
  • 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: Replace existing file with zero byte version with slight name change  (Read 9312 times)

magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 178
    • View Profile
    • Donate to Member
I have in multiple directories on a drive with files I once created as placeholders for later replacement with the correct file, and also reserving physical drive space.

They are identified in the name by " [PLACEHOLDER]"

What I am trying to do is bring all these files down to Zero Byte.

Then change the file type whatever it may be to ".placeholder"

Then remove " [PLACEHOLDER]" from the filename
 

An all in one solution would be great, but I can achieve the last two with Bulk Rename Utility in a couple of passes, so not a major issue.

Any thoughts.
Why an I Magician62? Because Magician1 thru 61 were gone. :)

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,612
    • View Profile
    • Donate to Member
Re: Replace existing file with zero byte version with slight name change
« Reply #1 on: December 26, 2015, 12:27 PM »
Why would you want to create filenames in advance if they differ from the filename to be used eventually?

OT: Reserving space for future filecontent won't work using 0-byte files, as no actual diskspace is claimed by those files, only a directory-entry. Write at least 1 byte and a single cluster (4 KB on most systems) is used.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Replace existing file with zero byte version with slight name change
« Reply #2 on: December 26, 2015, 12:31 PM »
I have in multiple directories on a drive with files I once created as placeholders for later replacement with the correct file, and also reserving physical drive space.

They are identified in the name by " [PLACEHOLDER]"

What I am trying to do is bring all these files down to Zero Byte.

Then change the file type whatever it may be to ".placeholder"

Then remove " [PLACEHOLDER]" from the filename
 

An all in one solution would be great, but I can achieve the last two with Bulk Rename Utility in a couple of passes, so not a major issue.

Any thoughts.

To confirm:

1) You have files like with "[PLACEHOLDER]" somewhere in the name, e.g., myfile [PLACEHOLDER].ext
2) These files currently occupy some amount of space, i.e., they're non-zero byte files.
3) Assuming the filename in #1, you want it to be: myfile.placeholder
4) You then want this new file to be zero-byte.  Basically, create myfile.placeholder as zero-byte and, if successful, delete the original myfile [PLACEHOLDER].ext

Correct?

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Replace existing file with zero byte version with slight name change
« Reply #3 on: December 26, 2015, 12:38 PM »
Why would you want to create filenames in advance if they differ from the filename to be used eventually?

It sounds like his current files DO reserve space (probably with random file data...doesn't matter how, really) and he wants to reclaim the space, but still keep a record, by making the new placeholder file (with a slightly different name) zero-byte.

magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 178
    • View Profile
    • Donate to Member
Re: Replace existing file with zero byte version with slight name change
« Reply #4 on: December 26, 2015, 12:44 PM »
Hi Jody, the current format is " [PLACEHOLDER].ext" so always immediately before the extension and in the square brackets. .placeholder will be the new extension, so I can filter on that in future.

As mentioned though I can do the rename elsewhere quite easy. Getting the zero byte files is the hard bit. I can even drag drop them in bulk to a util that replaces the file with zero byte


Ath

The reason for creating files in advance gave the ability to see what is missing, using PLACEHOLDER provided a simple, and filterable visual aid to identify those files, which may have been of different length to allow for the expected file size.

I don't expect a zero byte file to reserve drive space. The methodology has changed with falling storage costs and there is now at least 100Gb reserved space on the drive should the missing files, though unlikely, appear.
Why an I Magician62? Because Magician1 thru 61 were gone. :)

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Replace existing file with zero byte version with slight name change
« Reply #5 on: December 26, 2015, 01:27 PM »
Please test this AutoHotkey snippet on some copies of your files first.  Change the variables as needed.

Code: Autohotkey [Select]
  1. ; DO NOT put this script in the same folder as the files to be renamed.
  2.  
  3. ; Variables.
  4. bRecursive := FALSE           ; Change to TRUE if desired.
  5. sPath      := "c:\tmp\11\*.*" ; Change as necessary.
  6.  
  7. ; Process files.
  8. Loop, % sPath, 0, % bRecursive ; Iterate over files.
  9. {
  10.     ; Crack filepath.
  11.     SplitPath, A_LoopFileFullPath, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
  12.    
  13.     If InStr( OutFileName, " [PLACEHOLDER]" ) ; If " [PLACEHOLDER]" exists in filename.
  14.     {
  15.         ; Strip out " [PLACEHOLDER]" text from original filename.
  16.         StringReplace, OutNameStripped, OutNameNoExt, %A_Space%[PLACEHOLDER],
  17.        
  18.         ; Create zero-byte file with new name & extension.
  19.         FileAppend, % "", % OutDir . "\" . OutNameStripped . ".placeholder"
  20.        
  21.         ; If new file creation was successful, delete original placeholder file.
  22.         If ! ( ErrorLevel )
  23.         {
  24.             FileDelete, % A_LoopFileFullPath
  25.         }
  26.     }
  27. }
  28.  
  29. MsgBox, Done.


magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 178
    • View Profile
    • Donate to Member
Re: Replace existing file with zero byte version with slight name change
« Reply #6 on: December 26, 2015, 03:01 PM »
Hi Jody, as it's getting late in the evening, will test in the morning and report back, many thanks.


Also you may not have seen my bug comment on Files2Folders, , last page
https://www.donation...opic=19770.msg393594
Why an I Magician62? Because Magician1 thru 61 were gone. :)

magician62

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 178
    • View Profile
    • Donate to Member
Re: Replace existing file with zero byte version with slight name change
« Reply #7 on: December 26, 2015, 04:47 PM »
So I went ahead and tried it, and although a little sleepy I got their in the end, was having issues with sPath syntax. I have now added multiple replacements as I realised I hade used more than one coding. Many thanks for your help.
Why an I Magician62? Because Magician1 thru 61 were gone. :)

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,641
    • View Profile
    • Donate to Member
Re: Replace existing file with zero byte version with slight name change
« Reply #8 on: December 26, 2015, 04:55 PM »
robocopy <source> <dest> /CREATE /E /np /nfl /ndl /njh /njs

eg. robocopy D:\harry K:\fred /CREATE /E /np /nfl /ndl /njh /njs

That will create an exact copy of a directory tree populated with zero byte files in a very short time, (usually a few seconds).

Then you can use a bulk renamer afterwards if you want another alternative.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Replace existing file with zero byte version with slight name change
« Reply #9 on: December 26, 2015, 05:14 PM »
So I went ahead and tried it, and although a little sleepy I got their in the end, was having issues with sPath syntax. I have now added multiple replacements as I realised I hade used more than one coding. Many thanks for your help.

Great to hear.  Thank you for the donation as well.  Much appreciated.

TaoPhoenix

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 4,642
    • View Profile
    • Donate to Member
Re: Replace existing file with zero byte version with slight name change
« Reply #10 on: December 26, 2015, 08:23 PM »
Why would you want to create filenames in advance if they differ from the filename to be used eventually?

OT: Reserving space for future filecontent won't work using 0-byte files, as no actual diskspace is claimed by those files, only a directory-entry. Write at least 1 byte and a single cluster (4 KB on most systems) is used.

I am curious about the side tangents of all of this.

- I create files I often label (((something))) SHELL to remind me both that something needs to go there but that is a blank file. And since I don't worry about 4-7kb, I tend to use text files, because then I can put in a memo of "what was I *thinking?!*

- Do Zero Byte files show up in Directory Readers?

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,612
    • View Profile
    • Donate to Member
Re: Replace existing file with zero byte version with slight name change
« Reply #11 on: December 27, 2015, 04:20 AM »
I am curious about the side tangents of all of this.

- I create files I often label (((something))) SHELL to remind me both that something needs to go there but that is a blank file. And since I don't worry about 4-7kb, I tend to use text files, because then I can put in a memo of "what was I *thinking?!*
I'm just trying to find the reasoning for this kind of workflow. But maybe I'm not working often enough with files-in-directories projects to see this at a glance. Now that it's somewhat more explained, I'm getting the hang of it.  ;)

- Do Zero Byte files show up in Directory Readers?
Why would they not? Even a zero-byte file is a file, and the name does hold information. If they don't show up, the directory reader is flawed, IMHO.