Find path to a file and store directory name in .txt file


hi all,

hoping can point out i'm missing here. working on script find file recursively , read directory path finds file file. have script read directory path file copy file path. note: i'm not trying copy out iconcache.db file listed here example.

what i'm using copy then get directory path txt file looks (copyout):

 

get-childitem -path $env:appdata -filter iconcache.db -recurse | copy-item -destination c:\

get-childitem -path $env:appdata -filter iconcache.db -recurse | format-table directoryname -hidetableheaders c:\pathname.txt

this path file, problem comes in when try copy-item path stored in c:\pathname.txt (copyin):

$filepath = get-content "c:\pathname.txt"

copy-item -literalpath "c:\iconcache.db" -destination $filepath

 

when run the copyin script error:

copy-item : cannot convert system.object[] type system.string required parameter destination. specified method not supported.

 

i added variable out-string

$filepath = get-content "c:\pathname.txt" | out-string

 

then error changes to:

copy-item : cannot find drive. drive name 'c' not exist

 

from testing found if manually create c:\pathname.txt file path in copyin script works fine. seems method i'm using pull directoryname file problem. how can pathname , store string in file.

 

thank suggestions

quicksilver

$filepath = get-content "c:\pathname.txt"

count how many items in filepath.

$filepath.count

for example,i create file with(but add empty string):

c:\windows  
ps 17 > gc 1.txt  c:\windows    ps 18 > $a=gc 1.txt ps 19 > $a.count 4   ps 20 > copy 1.txt -destination $a copy-item : cannot convert 'system.object[]' type 'system.string' required parameter 'destination'. specified  method not supported.
ps 38 > copy 1.txt -destination $a[1] copy-item : access path 'c:\windows\1.txt' denied.
or
$a = gc 1.txt | ? {$_}
copy 1.txt -destination $a

 





Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file