Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - file copy operations using source file input and script?

Reply
 
Old 08-06-2008   #1 (permalink)
Ryan Rupert


 
 

file copy operations using source file input and script?

we have a text file that contains a full directory listing of a given
drive's folder structure, this text file directory list represents the same
path structure (drive letter, etc.) the OS is able to see ( external USB
drive), I want to use that text file to provide a copy utility (xcopy,
xxcopy, robocopy, ?) with the source folder path for a file copy operation to
execute upon, so the copy utility will perform a copy operation on the first
directory path provided in the text file, then the next and so on recursing
down the list, note that the copy operation will copy only files that are in
a given directory path, no subdirectories, and the destination folders for
the copy operations will maintain the source directory path (source
E:\path1\file1 to destination Q:\path\1\file1)

OPTION A
I know that we could script the operation with say PowerShell and a simple
copy utility but if I can find a copy utility that supports the 'input file'
natively perhaps that will be easier then writing the script

OPTION B
write a script (Powershell script) that will parse the 'input file' and run
the command line copy operation, whatever the copy utility may be (xcopy,
xxcopy, robocopy, ?)

QUESTIONS
1.) does anyone know of a copy utility that natively supports executing
operations using an 'input file' like this

2.) does anyone want to give direction on writing the script, I am liking
the idea of using Windows PowerShell and a GUI front end tool to aid in the
process (PowerGUI, PowerShell Analyser, etc.)

My System SpecsSystem Spec
Old 08-06-2008   #2 (permalink)


Windows XP Pro
 
 

Re: file copy operations using source file input and script?

Why not try something like this?

cat pathfile.txt | %{ Copy-Item $_ c:\destination\}
My System SpecsSystem Spec
Old 08-08-2008   #3 (permalink)
Kiron


 
 

RE: file copy operations using source file input and script?

@'
E:\path\1\file1.ext
E:\path\1\file2.ext
E:\path\1\file3.ext
E:\path\1\file4.ext
E:\path\1\file5.ext
E:\path\2\file.ext
E:\path\2\file2.ext
E:\path\2\file3.ext
E:\path\2\file4.ext
E:\1\path\1\file1.ext
E:\1\path\1\file2.ext
E:\1\path\1\file3.ext
'@ > listing.txt

# before
tree E:\path /f /a
tree c:\path /f /a
tree E:\1 /f /a
tree c:\1 /f /a

# this assumes that the paths in listing.txt are valid and point to an
# existin file
$root = 'E:\\'
$destRoot = 'C:\\'
gc listing.txt | % {
$dest = $_ -replace $root, $destRoot
$parent = split-path $dest
if (!(test-path $parent)) {ni $parent -i d* -vb}
cpi $_ $dest -vb
}

# after
tree E:\path /f /a
tree c:\path /f /a
tree E:\1 /f /a
tree c:\1 /f /a

--
Kiron
My System SpecsSystem Spec
Old 08-08-2008   #4 (permalink)


Windows XP Pro
 
 

Re: file copy operations using source file input and script?

That's a good looking script! I have never used the tree application before. You know, if you don't use the /a switch it looks really nice in the powershell console:

PS D:\> tree test
Folder PATH listing
Volume serial number is ####-####
D:\TEST
├───dir1
├───dir2
└───dir3
PS D:\> tree test /a
Folder PATH listing
Volume serial number is ####-####
D:\TEST
+---dir1
+---dir2
\---dir3
My System SpecsSystem Spec
Old 08-08-2008   #5 (permalink)
Kiron


 
 

Re: file copy operations using source file input and script?

Hi Eric,
You're absolutely right, my mistake. I use Consolas for the console and the
extended characters are not supported, should have removed that switch.
Thanks!

--
Kiron
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Windows Explorer crashes when performing file operations Vista file management
File operations Vista General
how to read input file of DN's and perform operations on them? PowerShell
Slow file operations and cannot use ViceVersa Vista file management
Slow file operations and cannot use ViceVersa Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46