Renaming a new folder file to the next incremental number with powershell script -
i appreciate should first mention have been unable find specific solutions , new programming powershell, hence request
i wish write (and later schedule) script in powershell looks file specific name - rfunnel , renames r0000001. there 1 of such 'rfunell' files in folder @ time. when next script run , finds new rfunnel file renamed r0000002 , on , forth
i have struggled weeks , seemingly similar solutions have come across have not been of - perhaps because of admittedly limited experience powershell.
others might able less syntax, try this:
$rootpath = "c:\derp" if (test-path "$rootpath\rfunnel.txt") { $maxfile = get-childitem $rootpath | ?{$_.basename -like "r[0-9][0-9][0-9][0-9][0-9][0-9][0-9]"} | sort basename -descending | select -first 1 -expand basename; if (!$maxfile) { $maxfile = "r0000000" } [int32]$filenumberint = $maxfile.substring(1); $filenumberint++ [string]$filenumberstring = ($filenumberint).tostring("0000000"); [string]$newname = ("r" + $filenumberstring + ".txt"); rename-item "$rootpath\rfunnel.txt" $newname; }
Comments
Post a Comment