Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, October 28, 2013 2:32 PM | 1 vote
Hi, I have some variables (filenames), examples:
test1.txt
test2.html
What i need, is some regex/substring command to remove everything right for the .
This is a part of a acript to compress a lot of files.
So basically this is what I need:
$a = test1.txt
b= test1.7z
All replies (8)
Monday, October 28, 2013 2:36 PM ✅Answered | 1 vote
$fileName="c:\folder1\folder1\test.txt"
$newExtension="zip"
[io.path]::ChangeExtension($fileName,$newExtension)
Monday, October 28, 2013 2:38 PM ✅Answered
$fileName="c:\folder1\folder1\test.txt" $newExtension="zip" [io.path]::($fileName,$newExtension)
Looks like you're missing a method name in there. Were you going for [System.IO.Path]::ChangeExtension($filName, $newExtension) ?
Monday, October 28, 2013 4:38 PM ✅Answered
Hi! Sorry for really misleading title... mondays .. :)
all i actually want is to either:
1: remove all characters that is to the right of the . (dot)
2: change the characters to the right of the . (dot) to "7z
both ways work for me :)
Then Dirk's suggestion of using [System.IO.Path]::ChangeExtension will work. Pass a path as the first argument, and "7z" as the second.
Monday, October 28, 2013 2:34 PM
I'm a little confuse on what you are asking for, are you saying you want to change the file extension?
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
Monday, October 28, 2013 2:49 PM
Does simply changing .txt to .zip actually compress the file?
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
Monday, October 28, 2013 2:51 PM
That method doesn't modify the file on disk. The System.IO.Path class just contains some handy methods for doing string manipulation of file system paths (typically working with Strings as both input and output.)
This seems to be what the OP was asking for; just how to parse the file names and produce a new string with a different extension, rather than how to actually create a compressed archive.
Monday, October 28, 2013 2:57 PM
I agree with you David, but he did also mention "This is a part of a acript to compress a lot of files.", which if he is under the impression, that simply changing an extention will compress for him, then that is incorrect information.
If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
Monday, October 28, 2013 4:34 PM
Hi! Sorry for really misleading title... mondays .. :)
all i actually want is to either:
1: remove all characters that is to the right of the . (dot)
2: change the characters to the right of the . (dot) to "7z
both ways work for me :)