INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Clear all html file content for eentire website

Clear all html file content for eentire website

(OP)
Hi,

I have a complete website, about 150 html & php pages.

I need some way of going through every html file and removing all content.  The purpose of this is to create a totally blank page for each of the pages.

So, lets say I have the following files...

Main.html, One.html, Two.html, dog.php, cat.php etc etc

I need to remove all code from each of the pages, whilst leaving the file name and folder structure in tact.

I need something like a Find and Replace hack, that will open each file, remove all of the content, then save it.

Does anyone have any idea how I might do this?

It would take me all day to open each file individually and delete the content, so any script or hack would be much appriciated.

Thanks,

Tony

RE: Clear all html file content for eentire website

Simple enough:

I assume you also have local copies your file and folder structure?

The do it locally and overwrite all files with those you emtpied locally...

e.g. as vba code
==>

CODE

sub clearall()
dim fso, fol, f
dim a as integer

set fso =createobject("Scripting.filesystemobject")
Set fol = fso.GetFolder("xyz")

For Each f In fol.Files
    a = FreeFile
    Open f.Name For Output As a
    Print #a, ""
    Close a
Next f

set f= nothing
set fol=nothing
set fso=nothing
End sub

You might have to adapt it if your files are spread over several sub folders, of course.

Then you best post in the respective forum, e.g. the
VBScript forum329 or the VBA forum707

Hope this helps.

Cheers,
Andy

Help us, join us, participate
IAHRA - International Alliance of Human Rights Advocates

RE: Clear all html file content for eentire website

(OP)
Brilliant!!

Thanks MakeItSo, this sounds great.

Sorry for posting this in the wrong forum, I did search through a few, but honestly couldn't work out where this was best placed.  

I have one last question if I may.

I have never used any VBA code, so I honestly don't have a clue how to use this wonderful bit of code you have written for me.

Could you please point me in the right direction for instructions on how to use this code.

Thanks again,

Tony

RE: Clear all html file content for eentire website

Sure Tony!

You can run this code from any Office application.
- Open e.g. Word, hit Alt+F11 or Tools->Macros->Visual Basic Editor
- Paste the code and replace "xyz" with the correct folder name or replace that code line with

CODE

Dim buf as String
...
buf=Inputbox("Please enter full path to HTML files")
Set fol = fso.GetFolder(buf)
...

In case your HTML are spread in subfolders, but only one level deep, you can also add this:

CODE

Dim sf
...
For each sf in fol.SubFolders
  For Each f In sf.Files
      a = FreeFile
      Open f.Name For Output As a
      Print #a, ""
      Close a
  Next f
Next sf
...

pipe

Glad it helps you!

Cheers,
Andy

Help us, join us, participate
IAHRA - International Alliance of Human Rights Advocates

RE: Clear all html file content for eentire website

(OP)
Sorry to be a pain Andy,

Thanks for your instructions.  I'm getting close now I know, but nothing appears to happen to the files.

Are you sure that this section is correct?

CODE

For Each f In fol.Files
    a = FreeFile
    Open f.Name For Output As a
    Print #a, ""
    Close a
Next f

I have run a debug, and it appears to go through each of the files in the folder I specify, but it doesn't actually do anything to the files.

I'm not familiar enough with VB to make any changes to the code so I'm at a bit of a loss right now.  I have a bit of code that should save me about 5 hrs work, but I can't get it to work.... :)

Any more ideas?

Once again, I appriciate your help immensely.

Tony

RE: Clear all html file content for eentire website

Hmmm.. interesting!
Obviously the print command does nothing if it has nothing to print...
ponder

OK, I have no choice but to test it... blllttt
New way, shorter and definitely working:

CODE

Sub clearall()
dim fso, fol, f, f1

set fso =createobject("Scripting.filesystemobject")
Set fol = fso.GetFolder("xyz")

For Each f In fol.Files
    Set f1 = fol.CreateTextFile(f.Name, Overwrite:=True)
Next f
Set f1 = Nothing
Set f = Nothing
Set fol = Nothing
Set fso = Nothing
End Sub

Now that should do it.
big smile


Good luck,
Andy

Help us, join us, participate
IAHRA - International Alliance of Human Rights Advocates

RE: Clear all html file content for eentire website

(OP)
Andy, what a star!!!

This is brilliant.

Works just the way I need it to.

Thank you very much.

Tony.

P.S
I wonder if anyone else would find this useful??
Everyone I asked thought this idea was totally stupid!

RE: Clear all html file content for eentire website

That might be because most people might think
"Why in a world would someone do this? Either you delete the file or you don't. But why keep all the framework?"

I assume you DO have a reason for this. Perhaps you want to automatically prefill all files with content stored elsewhere and get rid of the old stuff, perhaps....

Anyway: I have to find solutions to so many truly weird problems at my work, so I am hardly surprised of ANYthing anymore... blllttt

Glad it got you sorted!

Cheers,
Andy

Help us, join us, participate
IAHRA - International Alliance of Human Rights Advocates

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close