Solved

How to copy a directory and clear file contents ..

Posted on 2006-07-04
5
211 Views
Last Modified: 2012-05-05
Got a weird one for the gurus, I need an app or a way to clone a directory structure and have all the filenames intact, but the files to be empty or even 'corrupted' for want of a better word ... I could do it manually but it will be time consuming and want to know if there is an automated way of doing this.  

Cheers,

C180
0
Comment
Question by:Capricorn180
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:usachrisk1983
ID: 17039889
This could be done programatically with almost any type of scripting language - which Operating System are you looking to do this on?
0
 

Author Comment

by:Capricorn180
ID: 17039912
Thanks for the reply, I'm using windows xp sp2.

C180
0
 
LVL 13

Accepted Solution

by:
usachrisk1983 earned 125 total points
ID: 17039960
Drop this into a VBS file, change the old and new folder, and test.  Defaults not to overwrite if file exists, and there's no real error checking, so you'll want to beef it up if you're going to use it in any type of production environment:

strFolder = "c:\NoNav2.49"
strNewFolder = "c:\test"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)

on error resume next

CreateNewDirectory(objFolder.Path)

Set colFiles = objFolder.Files

For Each objFile In colFiles
  CreateEmptyFile(objFile.Path)
Next

ShowSubFolders(objFolder)

Sub ShowSubFolders(objFolder)
  Set colFolders = objFolder.SubFolders
  For Each objSubFolder In colFolders
    CreateNewDirectory(objSubFolder.Path)
    Set colFiles = objSubFolder.Files
    For Each objFile In colFiles
      CreateEmptyFile(objFile.Path)
    Next
   ShowSubFolders(objSubFolder)
  Next
End Sub

Sub CreateNewDirectory(oldDirectory)
 newDirectory = Replace(lcase(oldDirectory), lcase(strFolder), strNewFolder)
 wscript.echo "Create Directory " & newDirectory
 objFso.CreateFolder(newDirectory)
End Sub

Sub CreateEmptyFile(oldFile)
 newFile = Replace(lcase(oldFile), lcase(strFolder), strNewFolder)
 wscript.echo "Create New File " & newFile
 objFso.CreateTextFile newFile, false
End Sub

Credit to MSDN for the recursive directory search tips:
http://blogs.msdn.com/gstemp/archive/2004/08/10/212113.aspx
0
 

Author Comment

by:Capricorn180
ID: 17040011
Fan-bloody-tastic

Well done, exactly what I was after .. points r urs !

C180
0
 
LVL 13

Expert Comment

by:usachrisk1983
ID: 17040017
Thanks, glad it worked!
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A bootable USB key can be very handy now-a-days. My favorite USB key consists of our Windows 7 image, network card drivers (to connect up to a Ghost server), the latest BIOS updates for all of our PCs and CopyWipe (to erase a retired PC) Creating…
Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now