Solved

How to copy a directory and clear file contents ..

Posted on 2006-07-04
5
210 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hi, I've made you some graphics for a better understanding how RAID works. First of all, there are two ways a raid can be generated: - By hardware - By software What does that mean? This means: If you have a hardware RAID controller, there…
Problem description :  Some external hard disks / USB flash drives do not show actual space as mentioned in the factory settings. This is a common problem when you use an 8 GB USB drive to make it bootable to install a firmware/ driver on a serv…
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…

758 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

21 Experts available now in Live!

Get 1:1 Help Now