Solved

How to copy a directory and clear file contents ..

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best Practise to add /remove lun  vSphere 4.x,5.x,6.x 4 105
Windows Server failure RAID 31 80
VMotion Direct Attached Storage 9 97
VMWare vSAN 5 28
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…
Lets start to have a small explanation what is VAAI(vStorage API for Array Integration ) and what are the benefits using it. VAAI is an API framework in VMware that enable some Storage tasks. It first presented in ESXi 4.1, but only after 5.x sup…
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…

730 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