Showing posts with label Batch File. Show all posts
Showing posts with label Batch File. Show all posts

Friday, October 4, 2013

Renaming your recursive files and folder using a batch file.

Initially I was using a 3rd party software to do all the renaming work. But as I proceed, I ended up searching high and low for a method using a batch file (*.bat) to do all the tedious work. Therefore, after playing and modifying the code, I have ended up with this.

@echo off
setlocal enabledelayedexpansion
REM for renaming of recursive folders, sub folders
for /d /r %%f in (*.*) do (
set fn=%%~nxf

REM replace all the . with __ in the folder names (excludes extensions)
if not [!fn!]==[] ( 
if not ["%%~nxf"]==["!fn:.=__!"] ( 
echo ren "%%~f" "!fn:.=__!" 
ren "%%~f" "!fn:.=__!" 
)
)
REM replace all the -interface with nothing in the folder names
REM (excludes extensions) add a I in front of the folder name
if not [!fn!]==[] ( 
if not ["%%~nxf"]==["!fn:-interface=!"] ( 
echo ren "%%~f" "I!fn:-interface=!" 
ren "%%~f" "I!fn:-interface=!" 
)
)
)

REM for renaming of recursive files
for /r %%f in (*.*) do (
set fn=%%~nf

REM replace all the - with __ in the file names (excludes extensions)
if not [!fn!]==[] ( 
if not ["%%~nxf"]==["!fn:-=__!%%~xf"] ( 
echo ren "%%~f" "!fn:-=__!%%~xf" 
ren "%%~f" "!fn:-=__!%%~xf" 
)
)
REM replace all the -interface with nothing in the file names
REM (excludes extensions) add a I in front of the file name
if not [!fn!]==[] ( 
if not ["%%~nxf"]==["!fn:-interface=!%%~xf"] ( 
echo ren "%%~f" "I!fn:-interface=!%%~xf" 
ren "%%~f" "I!fn:-interface=!%%~xf" 
)
)
)
pause

* Click here to download the batch file that I have listed in this posted.
^ Click here to find out more about batch files in Windows.
~ Click here to find out the difference between %% and !! in a batch file.

Thursday, July 18, 2013

One of Windows OS missing component - Rename Multiple Filenames

Sometimes renaming a list of files can be pretty annoying and it gets more and more frustrating when there are a lot of files. And this can be pretty disturbing to the type of people that prefer to rename their filename with something meaningful. Therefore you can consider the following softwares.

  • A.F.5
    • I'm using this in the office. Basically, the interface of this software is pretty simple and although it doesn't come with a lot of features, but it is already more than enough.
  • Bulk Rename Utility
    • As I was browsing through blogs, discussion boards, etc, this seems to be one of the hottest alternative. It can even support filename replacement using Regular Expressions. However, the interface looks kinda squeezy to me. =.=

Friday, July 12, 2013

Creating a custom Service

Well, basically if you are using a Windows server or you are doing a lot of development work, you might be running a lot of services locally. (Ex: Apache, WAMP, etc...) Imagine how much time you can save by creating a Service that will start these programs automatically.

Steps for creating a new Windows Service
Before moving on any further, you will need to grab hold of these 2 files first.
They are instsrv.exe and srvany.exe.

Click here to download the files now.
Click here to download the original package from Microsoft.
(If you are using the package from Microsoft,
you will need to extract the files from the package.)

Step 1 - Open up the Windows Start menu, enter cmd into the
Search programs and files field, Right-Click on the program
cmd.exe and select Run as Administrator.

Step 2 - Enter the following into the Command Prompt window.

"{yourPath}\instsrv.exe" {name} "{yourPath}\srvany.exe"
Replace {yourPath} with the directory that has the files instsrv.exe and srvany.exe.
Replace {name} with the Name of the new Service that you are going to create.

And there you go, you have successfully created a new Empty Service.

Step 3 - Open up the Windows Start menu, enter regedit into the
Search programs and files field and run the program regedit.exe.

Step 4 - Look for the new Service under the following directory.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\{name}
Replace {name} with the Name of the new Service that you have created.

Step 5 - After selecting the new Service that you have created, Right-Click and
create a new Key. Rename the new Key as Parameters

Step 6 - Under Parameters add a few new String Value.

Step 7 - Entering some values
NameTypeData
ApplicationREG_SZ{the full path of your application}
Ex: G:\service\run_notepad.bat
AppDirectoryREG_SZ{the path to your application}
Ex: G:\service\

Step 8 - Open up the Windows Start menu, enter services into the
Search programs and files field and run the program Services.

Step 9 - Locate and open up the new Service that you have created.

Step 10 - You can set the Startup Type to either Automatic or
Automatic (Delayed start). (Automatic will start the Service
when Windows boots up. Automatic (Delayed start) will start 2 minutes
after the last Automatic Service has been executed.)

On top of that, some programs will only run smoothly with a particular user
account. That's where the Log On tab comes in. You can specify the
User Account Credentials that you are going to use when you run this Service.

Step Remove - To remove a Service,
type the following command in Command Prompt window.

"{yourPath}\instsrv.exe" {name} REMOVE
Replace {yourPath} with the directory that has the file instsrv.exe.
Replace {name} with the Name of the Service that you are going to delete.

And there you go, you have successfully removed a Service.