ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

I need help creating a new Directory structure including files from a text file.

(1/1)

sheriff28:
I need help in creating a batch file or similar that will make a Folder/Sub Folder structure and add the relative files to these new locations.

Below is a text file representing a small part of the structure that I wish to create.
The first comma delimiter represents the Folder and Sub Folders that I wish to create under a top level Folder called DATABASE DATA.
The second comma delimiter represents the name of the actual File.
The third comma delimiter represents the location of the files to import into the new Folder structure.

"File Samples\Type\Multi Page Scans,""milk cart.jpg"",""c:\users\fss\desktop\filecenter data\file samples\type\multi page scans\milk cart.jpg"""
"File Samples\Type\Multi Page Scans,""15_1.TIF"",""c:\users\fss\desktop\filecenter data\file samples\type\multi page scans\15_1.tif\15_1.tif"""
"File Samples\Type\Colour Scans,""montage.bmp"",""c:\users\fss\desktop\filecenter data\file samples\type\colour scans\montage.bmp"""
"File Samples\Type\Colour Scans,""NIAGRA.jpeg"",""c:\users\fss\desktop\filecenter data\file samples\type\colour scans\niagra.jpg"""
"File Samples\Type\Colour Scans,""Welcome Scan.jpg"",""c:\users\fss\desktop\filecenter data\file samples\type\colour scans\welcome scan.jpg"""
"File Samples\Type\Colour Scans,""SHOOTAA.TIF"",""c:\users\fss\desktop\filecenter data\file samples\type\colour scans\shootaa.tif"""
"File Samples\Type\Colour Scans,""jamesc.bmp"",""c:\users\fss\desktop\filecenter data\file samples\type\colour scans\jamesc.bmp"""
"File Samples\Type\Colour Scans,""teeth.jpg"",""c:\users\fss\desktop\filecenter data\file samples\type\colour scans\teeth.jpg"""
"File Samples\Type\MS Office Documents,""KUNDI  DAN 1.docx"",""c:\users\fss\desktop\filecenter data\file samples\type\ms office documents\kundi  dan 1.docx"""
"File Samples\Type\MS Office Documents,""Save & Invest.doc"",""c:\users\fss\desktop\filecenter data\file samples\type\ms office documents\save & invest.rtf"""
"File Samples\Type\MS Office Documents,""2003.05.01 Scanning Index.csv"",""c:\users\fss\desktop\filecenter data\file samples\type\ms office documents\2003.05.01 scanning index.csv"""
"File Samples\Type\MS Office Documents,""ec customer breakdown.xls"",""c:\users\fss\desktop\filecenter data\file samples\type\ms office documents\ec customer breakdown.xlsx"""

Shades:
Besides a missing attachment, this request does sounds like homework to me...anyway, the following links show you examples and ideas about the use of strings/arrays in Windows batch scripts:
Create Lists or arrays in Windows batch (SuperUser website (StackOverflow))
How to use array in Windows batch programming
Using arrays in batch files (Rob van der Woude website, a good resource for batch script creation)
Creating array into batch (example script)
Arrays, structures and linked lists in batch files (dostips website, another good resource for batch script creation)
Arrays, linked lists and other data structures in cmd.exe (another StackOverflow page explaining do's and don'ts)

These links should get you going :)

Target:
and have a look in the coding snacks, things like this have been done several times already

4wd:
I think it would be a lot easier to do it using Powershell, look at the commandlets:
Import-Csv  (read the CSV file)
New-Item     (create folder structure)
Copy-Item    (copy file to destination or use Move-Item)

This Stack Overflow post pretty much answers how to do it in Powershell:
http://stackoverflow.com/questions/11885246/how-do-i-loop-through-a-line-from-a-csv-file-in-powershell

To get you started, this will create a folder structure using the info in the CSV:

--- Code: PowerShell ---$path = "k:\test.csv"Import-Csv -path $path | ForEach-Object {  foreach($property in $_.PSObject.Properties) {    $stuff = ($property.Value).Split(",")    New-Item -Path ("K:\DATABASE DATA\" + $stuff[0]) -ItemType Directory | Out-Null  }}
I need help creating a new Directory structure including files from a text file.

No error checking or pre-existing path checking.

The second item in the CSV isn't needed, you only need to copy/move the original file (third item) to the new structure.

MilesAhead:
4wd's Power Shell script looks like it has the problem covered.  For general purpose directory creation with a long parent directory chain I have a utility on my page CreateDir

It has a /q switch; quiet mode for use in batch files.  It is written in AutoIt3 that has a DirCreate() function that creates any missing folders in the chain when creating the target folder, without any programmer intervention needed.  See the included Readme.txt file for examples.

Navigation

[0] Message Index

Go to full version