josephh610
asked on
How do you copy a text file list of files from one directory to another in powershell?
How do you copy a text file list of files from one directory to another in powershell?
I have a text file:
c:\temp\LOF.txt
It has a list of files and their directories:
C:\test1.txt
C:\test2.txt
C:\test3.txt
I need to copy this list to another destination:
C:\tempfiles\
And i need to do it in powershell, what is the easiest way to do this?
I have a text file:
c:\temp\LOF.txt
It has a list of files and their directories:
C:\test1.txt
C:\test2.txt
C:\test3.txt
I need to copy this list to another destination:
C:\tempfiles\
And i need to do it in powershell, what is the easiest way to do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I am not sure what you are asking:
Are you asking to create a new text file showing original path and new destination ?
Are you asking to create a new text file showing original path and new destination ?
ASKER
I just figured out that i need to grab both the source and target from the test file.
So if in my text file I have the source and target and i need to grab those for the copy command.
example:
Source Target
c:\test1.txt|c:\tempflies1
C:\test2.txt|c:tempfiles2
So it would copy:
C:\test1.txt to c:\tempflies1
what would that code look like?
So if in my text file I have the source and target and i need to grab those for the copy command.
example:
Source Target
c:\test1.txt|c:\tempflies1
C:\test2.txt|c:tempfiles2
So it would copy:
C:\test1.txt to c:\tempflies1
what would that code look like?
ASKER
Or maybe use a -> to divide the source and target.
Sorry was not monitoring.
You can probably just save this as a csv:
Source Target
c:\test1.txt|c:\tempflies1
C:\test2.txt|c:tempfiles2
You can probably just save this as a csv:
Source Target
c:\test1.txt|c:\tempflies1
C:\test2.txt|c:tempfiles2
import-csv file.csv -delimiter "|" | % {
copy $_.source $_.target
}
ASKER
I get this when i use this code.
Copy-Item : Cannot bind argument to parameter 'Path' because it is null.
At line:1 char:58
+ import-csv C:\temp\filelist.csv -delimiter "|" | % {copy $_.source $_.target}
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Copy-Item], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nErrorNull NotAllowed ,Microsoft .PowerShel l.Commands .CopyItemC ommand
Copy-Item : Cannot bind argument to parameter 'Path' because it is null.
At line:1 char:58
+ import-csv C:\temp\filelist.csv -delimiter "|" | % {copy $_.source $_.target}
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Copy-Item], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
your header in the csv should share the same delimiter:
Source|Target
c:\test1.txt|c:\tempflies1
C:\test2.txt|c:tempfiles2
or you can not have a header
c:\test1.txt|c:\tempflies1
C:\test2.txt|c:tempfiles2
and call it this way:
Source|Target
c:\test1.txt|c:\tempflies1
C:\test2.txt|c:tempfiles2
import-csv file.csv -delimiter "|" | % { copy $_.source $_.target}
or you can not have a header
c:\test1.txt|c:\tempflies1
C:\test2.txt|c:tempfiles2
and call it this way:
import-csv -delimiter "|" -Header Source,Target file.csv | % { copy $_.source $_.target}
ASKER
Thank you! that was perfect.
Cheers!
Cheers!
ASKER
c:\test1.txt|c:\tempflies1
C:\test2.txt|c:tempfiles2
and have it add that to the copy?