[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to copy a directory and clear file contents ..

Posted on 2006-07-04
5
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
A look at what happened in the Verizon cloud breach.
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…
Suggested Courses

656 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