Solved

How to copy a directory and clear file contents ..

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
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…
This Micro Tutorial will teach you how to reformat your flash drive. Sometimes your flash drive may have issues carrying files so this will completely restore it to manufacturing settings. Make sure to backup all files before reformatting. This w…

786 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