Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Script to Auto Rename Multiple Files in Windows Explorer

09 Nov 2014   #1
IndyColtsMan

Windows 7 32 bit
 
 
Script to Auto Rename Multiple Files in Windows Explorer

Is there a way to automate the renaming of multiple files in windows explorer which will also add the Julian date at the beginning of each file name.

I have a sign-in roster for my employees at work to digitally sign each day when the report to work and again before the depart. I have been taking a single PDF file and copy/pasting it into a folder for each month for as many days there are in the month. I manually change the file name to add each Julian date to the beginning so the employees will know which file to open for that particular day at work. I have 5 different sections so this becomes an extremely tedious task.

Please help.


My System SpecsSystem Spec
.
10 Nov 2014   #2
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Hi IndyColtsMan,

There sure is a way to rename files to your desire in an automated fashon via Windows scripting features.

Firstly, more information will be needed.

I need you to clarify or better explain what exactly your situation is. You must be precise in explaining what needs to happen to your input file A.pdf to get your output file B.pdf name.

If you could provide a sample directory tree of your situation, and/or even better; actual sample file names with paths to work with, it would really help.

 
My System SpecsSystem Spec
13 Nov 2014   #3
IndyColtsMan

Windows 7 32 bit
 
 



Attached Thumbnails
Script to Auto Rename Multiple Files in Windows Explorer-explorer-.jpg   Script to Auto Rename Multiple Files in Windows Explorer-explorer-b.jpg  
Attached Files
File Type: pdf Liaison Office.pdf (1,023.7 KB, 2 views)
My System SpecsSystem Spec
.

14 Nov 2014   #4
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by IndyColtsMan View Post
I hope this helps explain what I’m trying to do.
I understand what you're trying to achieve now and ... honestly, it doesn't sound easy to turn into a script, let alone a batch script -- the ideal way to automate thing in Windows. But I'll try my best.

Taking a guess at the folder structure implied; suppose it looks something like:

Code:
C:\somepath\documents\2014\November
With
Code:
C:\somepath\documents\2014\November\305 Liaison Office.pdf
being the file for the first of November, 2014. Correct? Because it has been 305 days since... 0/1/2014?


Is the location of the 'original' Liaison Office.pdf (the one that you copy and paste each month) in this directory tree somewhere? If not, where might its location be, relative from say C:\somepath\documents\2014? So that the script may access its location for copying.

The title of this thread is asking to rename muliple files in a folder. But as your situation stands, I reckon it would be of your best interest to extend what you're asking for, and instead, ask for a script that automatically lays out the folder structure for you for that month (or possibly even for that entire year) and copies and renames the correct amount of files as days in that month appropriately. Is this prefered?
My System SpecsSystem Spec
14 Nov 2014   #5
IndyColtsMan

Windows 7 32 bit
 
 

Pyprohly,

I have the original file in a separate directory on my hard drive. I have 5 different sections that I do this for (see below) and the actual folders that the employees access are on a shared network drive (V:\HTSI AFSB Kuwait (IZ) Staff Augmentation\ATTENDANCE TRACKER\Attendance Rosters) within another directory labeled as such for the month "305-334 (Nov) 2014". I could actually create another folder and place a copy of all five original files inside the Attendance Rosters folder.

I do believe your suggestion would be better. I would want the automated folders placed inside the folder labeled "Pending" as I only have the folder for the current month visible to the employees.

Does this help?


Attached Thumbnails
Script to Auto Rename Multiple Files in Windows Explorer-folders.jpg   Script to Auto Rename Multiple Files in Windows Explorer-folders-2.jpg  
My System SpecsSystem Spec
16 Nov 2014   #6
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Here's a script that answers your initial question:

Preview:
Code:
@echo off
setlocal EnableDelayedExpansion
REM Duplicate a file for as many days there are in the current month
REM And rename each file with a Julian date infront of the file name
pushd "%~dp0"
call :GetCurrDate
call :SetFebruary
call :GetMonthName %MM%
call :GetJulianDay %MM% %DD%
call :GetMaxDaysInMonth %MM%
call :GetMonthRange %MM%
REM Check that only one other file is in the folder
for /f "delims=" %%I in (' dir /b /a:-d "*.*" ^| find /v "%~nx0" ^| find /c /v "" ') do (
 if "%%I" NEQ "1" echo.& echo Error: Expected exactly 1 other file in directory.& timeout 2 >NUL& goto :eof
)
REM Copy files n number of times for days in current month
set counter=0
for /f "delims=" %%F in (' dir /b "*.*" ^| find /v "%~nx0" ') do (
 for /l %%I in (1,1,%DD_MaxDaysInMonth%) do (
  set /a counter+=1
  copy "%~dp0\%%~nxF" "%~dp0\tmp!COUNTER!%%~xF" >NUL
 )
set FileName=%%~nF
set FileExtn=%%~xF
del "%%~fF"
goto :break
)
:break
REM Rename files in folder
set counter=%MIN_JulianDayInMonth%
for /f "delims=" %%F in (' dir /b "*.*" ^| find /v "%~nx0" ') do (
 ren "%%~fF" "!COUNTER! %FILENAME%%FILEEXTN%"
 if !COUNTER!==%MAX_JulianDayInMonth% goto :break
 set /a counter+=1
)
:break
 
:End
popd
echo.&echo Success.
goto :eof
REM End
REM Functions below
:GetCurrDate
setlocal
 for /f "delims=" %%I in (' date /t ') do (
  set currDate=%%I
  set currDate=!CURRDATE: =!
  set currDate=!CURRDATE:~4!
 )
 for /f "tokens=1-3 delims=/" %%A in ("%CURRDATE%") do (
  set DD=%%A
  set MM=%%B
  set YYYY=%%C
  set Index=!MM!
 )
endlocal & set CurrDate=%CURRDATE%& set DD=%DD%& set MM=%MM%& set YYYY=%YYYY%&
goto :eof
:SetFebruary
setlocal
 set /a Leapyear=YYYY %% 4
 if %LEAPYEAR%==0 ( set Feb=29) else ( set Feb=28)
endlocal & set Feb=%FEB%
goto :eof
:GetMonthName MM
setlocal
 set Index=%1
 for /f "tokens=%INDEX%" %%M in (
  " January February March April May June
   July August September October November December "
 ) do set MM_Name=%%M
endlocal & set MM_MonthName=%MM_Name%
goto :eof
:GetJulianDay MM DD
setlocal
 set Index=%1
 set /a Index-=1
 for /l %%I in (1,1,%INDEX%) do call :GetJulianDay_Sub %%I
 set /a JulianDay+=%2
endlocal & set DD_JulianDay=%JULIANDAY%
goto :eof
:GetJulianDay_Sub
 for /f "tokens=%1" %%M in (
 " 31 %Feb% 31 30 31 30 31 31 30 31 30 31 "
 ) do ( set /a JulianDay+=%%M)
goto :eof
:GetMonthRange MM
setlocal
 set Index=%1
 
 call :GetMaxDaysInMonth %INDEX%
 set DD=%DD_MaxDaysInMonth%
 call :GetJulianDay %INDEX% %DD%
 set MAX_JulianDayInMonth=%DD_JulianDay%
 
 set DD=1
 call :GetJulianDay %INDEX% %DD%
 set MIN_JulianDayInMonth=%DD_JulianDay%
 
 set MonthRange=%MIN_JulianDayInMonth%-%MAX_JulianDayInMonth%
endlocal & set MIN_JulianDayInMonth=%MIN_JulianDayInMonth%& set MAX_JulianDayInMonth=%MAX_JulianDayInMonth%& set MonthRange=%MONTHRANGE%&
goto :eof
:GetMaxDaysInMonth MM
setlocal
 set Index=%1
 for /f "tokens=%INDEX%" %%M in (
  " 31 %Feb% 31 30 31 30 31 31 30 31 30 31 "
 ) do set DD_MaxDays=%%M
endlocal & set DD_MaxDaysInMonth=%DD_MaxDays%
goto :eof

Instructions:
1) Place the batch file and a single pdf in a directory of your choice.
2) Run the batch script.

Note: for a date such as 4/3/yyyy, '62' will be the Julian date displayed on the pdf. Would you like this number to be represented by 3 digits instead? E.g. '062'

Feel free to mark the thread as solved while a more complex script for your task is underway.

Meanwhile, thank you for supplying a directory tree, it helps visualise the situation. I'm almost on the same page as you are now, but I'm a little confused on where Liaison Office.pdf files are situated from the directory tree you describe. From what I'm getting, you're saying you do the tedious task of copying and renaming 'Liaison Office.pdf' 5 times each month for the 5 folders inside 'ATTENDANCE TRACKER'?


Attached Files
File Type: bat thread-no-351773_bat1_r1.bat (3.0 KB, 4 views)
My System SpecsSystem Spec
Reply

 Script to Auto Rename Multiple Files in Windows Explorer




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
VB script: Rename all files in a folder to a specified prefix
Hi, I'm trying to find help in entering paths and prefix's in my vb script. I am of course a newbie to visual basic and don't know where to enter the path and wording for prefix. Any help would be most appreciated. Rich
General Discussion
Windows Explorer File Help - I can't rename/move/delete certain files.
I hope this is the right place to post this... I have had this issue for a long time now, though, it only applies to video files... Anytime I try to rename/move/delete certain video files I get the error: "The action can't be completed because the file is open in Windows Explorer" I have...
Software
Script help - downloading files from multiple computers
Hi all, So i am new to scripting and I am having issues figuring out where to start. Hope someone can help. I have 20+ computers that I connect to and grab .txt files. I would like to create a bat file that will connect to the computers and download the files to my local. This will save me...
General Discussion
'Rename' gone from context menu for multiple files?
The ability to rename multiple files at once (by selecting all, right clicking them and click rename,) has disappeared from my context menu. I use it often to rename large batches of jpegs. How do I get it back? Thanks.
General Discussion
rename multiple files, bat file
rename files Nasha.Rasha.2010.720p.BluRay.Rus.HDCLUB.mkv.00 Nasha.Rasha.2010.720p.BluRay.Rus.HDCLUB.mkv.01 Nasha.Rasha.2010.720p.BluRay.Rus.HDCLUB.mkv.02 Nasha.Rasha.2010.720p.BluRay.Rus.HDCLUB.mkv.03 ... to Nasha.Rasha.2010.720p.BluRay.Rus.HDCLUB.mkv.000
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 12:46.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App