TechSpot

Copy folder structure and filename only

By yash321
Mar 9, 2010
  1. This Quesiton may be asked serveral times but i m looking for something crazy that's make no sense but that will help me in testing my REGEX programing

    I have a directoy :c:/testing

    in which there are serveral files or subfolder's which contain
    - movie files (.avi , .mpg , wmv)
    - some html file

    I want to copy the folder structure as well as it will also copy the file name of movie file and create textfile with same name of movie

    Like :

    Original Folder :

    c:\testing\folder1\abc.wmv
    c:\testing\folder2\folder2.2\folder2.3\bca.html
    c:\testing\folder3\folder3.2\xyz.avi

    i want output like this (Just create a empty textfile)

    c:\yash\folder1\abc.txt
    c:\yash\folder2\folder2.2\folder2.3\bca.txt
    c:\yash\folder3\folder3.2\xyz.txt


    Suggest me how to do

    - Any software
    - Any Trick
    - Any Dos prompt prograaming

    I just want to do this

    Thnx
     
  2. ravisunny2

    ravisunny2 TS Ambassador Posts: 2,057   +8

  3. jobeard

    jobeard TS Ambassador Posts: 13,446   +324

    that tool is a gui (so there's no automation)
    and the .TXT is created in the same dir as the original

    the languages that help here are Perl and PHP
    as a prototype (irrespective of language)
    Code:
    srcDir = c:\testing
    dstDir = c:\elsewhere
    changeDir($srcDir)
    foreach name ( readDir(.) ) do {
       if $name is dir {
          mkDir($dstDir\$name)
       } else {
          rootName = getRoot($name)  # for a name like [B]foo.avi[/B], capture the FOO
          ext     =  getExt($name)   # and isolate the existing AVI
          touch($dstName\$rootName.txt)   #creating an EMPTY \elsewhere\[B]foo.txt[/B]
          touch($dstName\$name.txt)   #creating EMPTY \elsewhere\[B]foo.avi.txt [/B]     
       }
    }
    
    this will ONLY work on the contents of $srcDir, ie will not descend into subdirs.
    for that, you need a mod for "recursive descent"
     
  4. ravisunny2

    ravisunny2 TS Ambassador Posts: 2,057   +8

    Neat.

    Sure Filenote it is a GUI.

    As for the txt file, xcopy can not just create the skeleton dir structure, but copy the txt file to it.

    For automation, one can even use a cmd file, but I personnaly consider that clumsy.

    yash321, is apparently not too well versed in programming, or he would not make this post.

    Why not put in the mod for "recursive descent", so he can use the code to meet his needs ?

    Personally, I'd write a 'c' or java routine, for the automation.

    Peace and goodwill.
     
  5. jobeard

    jobeard TS Ambassador Posts: 13,446   +324

    I'm working on a PHP implementation ...
     
  6. jobeard

    jobeard TS Ambassador Posts: 13,446   +324

    ... completing testing and documentation

    meanwhile you need to DL and install PHP for windows

    pick the Bin Install (PHP 5.3) for your architecture and install it at C:\PHP
    you may choose either {Non Thread Safe, or Non Thread Safe}

    I'll post the options necessary for the \PHP\php.ini with the tool
     
  7. jobeard

    jobeard TS Ambassador Posts: 13,446   +324

    the attachment contains
    description.txt of the invocation
    readme.txt containing
    • public release
    • sample results
    • requirements
    • recommended PHP install location and ini settings
    • and notes on Operational Issues
    the program RDescent.php
    and a DIRNAME for install testing​
     

    Attached Files:

  8. ravisunny2

    ravisunny2 TS Ambassador Posts: 2,057   +8

    Kudos, jobeard!

    Perhaps, there should be a section for "SmartPacks/Utilities/Tools" developed by members.
     
  9. SNGX1275

    SNGX1275 TS Forces Special Posts: 12,630   +321

    You guys are making it far too hard. Just do this from a DOS prompt (after navigating to the dir).
    Code:
    dir /s > listing.txt
     
  10. LNCPapa

    LNCPapa TS Special Forces Posts: 4,336   +280

    That'll just give you a text file with a directory and file listing from his starting point down. He wants the actual folders to be created elsewhere and empty placeholders for the actual files.
     
  11. jobeard

    jobeard TS Ambassador Posts: 13,446   +324

    btw: to retain some portion of the original source directory, the last parmature can be

    . (ie the period) to descend all subdirs

    or

    .\subdiname which will descend only that subdir (and everything therein) and
    create a result assuming (-t \index) of \index\subdirname\ and all descendant materials.

    If we assume that the current dir is My Pictures, then you can capture and keep the substructure of your pictures :)
     
     
  12. jobeard

    jobeard TS Ambassador Posts: 13,446   +324

    SNGX1275's solution has some merit -- HD space consumption

    the DIR /S solution creates ONE file with a minimum disk usage of one CLUSTER and expands minimally to contain all the names

    The RDescent.php solution creates zero byte-size files which still take ONE CLUSTER EACH. This will waste significant HD space as the number of files created increases.

    The content (eg: 06/20/2005 03:56 PM 394,025 bookmarks.txt) also provides more
    information about the original file, (date, time, size) but performing automation over that list
    could be an issue if all the O.P. needed was the file name (must read & parse).
     
  13. SNGX1275

    SNGX1275 TS Forces Special Posts: 12,630   +321

    Are you sure? Maybe because I didn't read in detail the replies, I just saw they involved a lot more complexities than a few characters from the DOS prompt. I just focused on this from the original post:
    Ok now after more carefully reading... I can see I wasn't correct.
     
Topic Status:
Not open for further replies.


Add New Comment

TechSpot Members
Login or sign up for free,
it takes about 30 seconds.
You may also...


Get complete access to the TechSpot community. Join thousands of technology enthusiasts that contribute and share knowledge in our forum. Get a private inbox, upload your own photo gallery and more.