Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Creating new folders with suffix

$
0
0

Hello, can someone  help me here.

I have a script for copying files from one server to other. For that task i am creating a new folder and copy all files there, this is the part of the script  which i am using for that,

    $date = get-date -format  "yyyy.MM.dd"
    $dstdir = "D:\Upload\$date"

    if (-not (Test-Path -Path $dstdir)) {

    new-Item -type Directory -path $dstdir

    ... }

The problem is that there a cases when i have to copy file multiple times during day. So i need to create another folder for them.So since i am using date for folder's name, the same name will be created already at the first time. So i need something like adding a suffix to the folder every time if there is already a folder with today's date. So lets say i have a folder with date 2015.01.08, next folder would be 2015.01.08_1, next 2015.01.08_2 and so on ..

Can someone help me with adding a suffix to a folder increasing by one every time ..

 

 

 

 

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles