1
param([String]$fileName)
$Target = "C:\Users\pb\Desktop\destination"

if (Test-Path $fileName)
{
Copy-Item $fileName $Target
} Else
{
"File does not exist"
}
2
  • You need to put a little more effort into your question. I'm pretty sure that I know what you are asking but to be honest with you your lack of effort sucks all the desire to answer right out of me. Where in the name do you want the date? A simple google search would have answered this including the duplicate question. Commented Jun 2, 2015 at 16:15
  • I had been google searching and then I was having trouble figuring out how the cases applied to mine. I've never used Powershell until now so my understanding of the syntax is limited even though I understand that it is supposed to be very simple. I figured it out Commented Jun 2, 2015 at 19:13

1 Answer 1

3

You could do something like this:

param([String]$fileName)

if (Test-Path $fileName)
{
  $file   = [io.path]::GetFileNameWithoutExtension($fileName)
  $ext    = [io.path]::GetExtension($fileName)
  $Target = "C:\Users\pb\Desktop\destination" + $file + $(get-date -f yyyy-MM-dd) + $ext
  Move-Item $fileName $Target
} 
Else {
  Write-Host "File does not exist!"
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.