Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get/set file attributes in PowerShell when the path\filename is longer than 260 characters

I am looking for a way to get and set file attributes (hidden and readonly) in PowerShell for files where the combined path and filename are longer than 260 characters. I know that the .NET classes don't support longer file paths; I've already tried that. Attrib doesn't work either. I get error "Parameter format not correct -". Likewise Dir doesn't work either.

I am using Robocopy to obtain the filenames. Robocopy has no issues with long paths. However, I can't use Robocopy to get/set attributes since I am just using the /L list mode of Robocopy.

Anyone have workarounds for PowerShell?

Update:

subst does not support extra-long paths. It does seem to work with partial paths though.

mklink requires local volumes.

net use does not support extra-long paths. It does seem to work with partial paths though.

New-PSDrive does not support extra-long paths, not even partial paths.

like image 669
Benjamin Hubbard Avatar asked Nov 11 '22 16:11

Benjamin Hubbard


1 Answers

I guess using subst command to map the path as a drive letter is worth a shot. It is based on the olden days of DOS and still works on Winndows like so,

subst k: c:\some\really\complex\path\with\too\many\subdirs\and\suff\...

If subst doesn't work, try sharing a directory close to the file and access it via UNC path.

like image 196
vonPryz Avatar answered Nov 14 '22 23:11

vonPryz