[jawsscripts] Re: script that adds numbers each time it is executed

  • From: Brian Vogel <britechguy@xxxxxxxxx>
  • To: jawsscripts@xxxxxxxxxxxxx
  • Date: Tue, 15 Nov 2016 21:38:11 -0500

Hamid,
           Is there anyone (yourself included) who's familiar with Windows
Power Shell scripting?  The script that appears below gives the outline of
precisely what you want to do, and I've run it in a test folder on my
machine, but it is very "quick and dirty."  It does no parameter checking
and has no safety elements built in so if you're not careful about being in
the folder you want to run it in it has the potential to wreak havoc.  So
much for the disclaimer.

           I would create a file somewhere that contains this script text
and name it something like Rename_for_Year.ps1.  You would then copy it to
the folder where the files need to be renamed, use the context menu to open
it with notepad to tweak the year in question, save the file, then bring up
the context menu with it selected and choose "Run with PowerShell."

---------------------------------------------------------------------------------------
# Use a foreach to loop through all the files in the current directory
# This method allows us to easily track the file name so we can report
# our findings by file if you wish to echo information about what's
happening

#Set the variable for the year you wish to use in the rename
$ryear=2015

#Set first number for renaming file to 1
$i=1

#For each file found in the current directory  (and that will include this
copy of the power shell script)
foreach($curfile in Get-ChildItem ".")
{
    #Rename the current file with a number prefix ($i), followed by the
rename year ($ryear),
    #followed by its original name ($curfile) with hyphens separating each
element
    #If you wish to just have file names like 1-2015, 2-2015, etc., then
strip the final hyphen and $curfile
    # variable in the rename line below
    Rename-Item $curfile $i-$ryear-$curfile
    $i++
}
----------------------------------------------------------------------------------------

This should give you something to start with.  This can also be
accomplished via a .bat file that would run under Command Prompt rather
than Power Shell, but the syntax is a bit messier (believe it or not)

Brian
-- 
*Bri the Tech Guy*          *http://britechguy.com ;<http://britechguy.com>*
brite <britechguy@xxxxxxxxx>chguy@xxxxxxxxx <britechguy@xxxxxxxxx>
  phone/text:  *(540) 324-5032*
"*If it's got you screaming, I'll help you stop!!*"


__________�

View the list's information and change your settings at 
//www.freelists.org/list/jawsscripts

Other related posts: