SOLVED Using a batch file to find and rename files.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
osburn383
Posts: 8
Joined: 25 Mar 2013 13:27

SOLVED Using a batch file to find and rename files.

#1 Post by osburn383 » 25 Mar 2013 14:11

I’m very much a novice when it comes to batch files.
Any help at all to point me down a path to solving this would be much appreciated.

The Problem 1:
I have around 15k CAD files i need to check the extension and rename to DGN.
Someway of have the batch file checks all the sub folders of the main CAD file and change and files that do not have the proper extension to DGN.

The file system is as follows:
L:\Michael\Organized Updated Drawings\32\CAD\A\32-A-009.DGN
The main structure is the bold section.

I have a directory legend with all the numbers and letters used in the file system.
You first have the number area the drawing is in and then if it’s a cad file, next are the letter(s) which determines what discipline it is (water, electric, etc).


The Problem 2:
I also have an additional 10k CAD files that where mass imported in a single folder to sort through. :cry:

Each file has varying extensions that denote what area the file belongs to in the paper mill I work for.

The old system would save them as such.
5232168419.70K
5213541516.30I
5516684651.80S

I need to change the extension of each file to DGN.
Like this:
5232168419.DGN
5213541516.DGN
5516684651.DGN

I did figure out how to create a list.txt of the files and pull that into excel.
I was using ="ren "&A1&" "&D1 to rename the extensions all to DGN.

I think i would be better to if i can place them in sub folders based on there original extension.

Such as if the file is like this one.
5516684651.80S
I would be great for the batch file to look at the extension first and the place it in its own sub folder called 80S and then change the extension to the proper DGN one.

I know this asking a lot at once but again looking for some direction.
Last edited by osburn383 on 26 Mar 2013 13:09, edited 4 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Using a batch file to find and rename files.

#2 Post by foxidrive » 25 Mar 2013 15:54

EDITED to remove extra quotes

Problem 2

Code: Select all

@echo off
for %%a in (*.*) do (
if /i not "%%a"=="%~nx0" (
md "%%~xa" 2>nul
move "%%a" "%%~xa\%%~na.DGN"
)
)
pause

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Using a batch file to find and rename files.

#3 Post by foxidrive » 25 Mar 2013 15:59

Problem 1

Run this and then examine renfiles.bat in notepad before renaming it to .bat and executing it.

Code: Select all

@echo off
del renfiles.bat.txt 2>nul
dir /a-d /b /s "L:\Michael\Organized Updated Drawings\" >file.tmp
for /f "delims=" %%a in (file.tmp) do >>renfiles.bat.txt echo ren "%%a" "%%~na.DGN"
del file.tmp

osburn383
Posts: 8
Joined: 25 Mar 2013 13:27

Re: Using a batch file to find and rename files.

#4 Post by osburn383 » 25 Mar 2013 21:55

Ok thanks for the quick response i will give it a go in the morning when i get to work.

osburn383
Posts: 8
Joined: 25 Mar 2013 13:27

Re: Using a batch file to find and rename files.

#5 Post by osburn383 » 26 Mar 2013 07:23

Wow that worked great!

Thanks so much fo the help.

It seems so easy with that lol.

Any good websites to help with learing more about how to type out a proper batch file?

I have been teaching myself html, css, java, This looks like a much needed skill to pick up for me.

Thanks again.

osburn383
Posts: 8
Joined: 25 Mar 2013 13:27

Re: SOLVED: Using a batch file to find and rename files.

#6 Post by osburn383 » 26 Mar 2013 07:56

The only thing i forgot to mention is that some of the folders are named like this:

27'16
29'32
29'32'35
19'22'25
11'12

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: SOLVED: Using a batch file to find and rename files.

#7 Post by foxidrive » 26 Mar 2013 08:31

osburn383 wrote:The only thing i forgot to mention is that some of the folders are named like this:

27'16
29'32
29'32'35
19'22'25
11'12



Is that for problem 1?

They should still allow the files within to be renamed. Filenames with non-english characters can be a problem.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Using a batch file to find and rename files.

#8 Post by foxidrive » 26 Mar 2013 08:33

EDITED to remove extra quotes.

foxidrive wrote:Problem 2


I edited that above.

osburn383
Posts: 8
Joined: 25 Mar 2013 13:27

Re: SOLVED: Using a batch file to find and rename files.

#9 Post by osburn383 » 26 Mar 2013 08:57

Sorry, yes that was for problem 1.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: SOLVED: Using a batch file to find and rename files.

#10 Post by foxidrive » 26 Mar 2013 09:01

osburn383 wrote:Sorry, yes that was for problem 1.


Is there a problem with it? Those folder names should not present an issue.

osburn383
Posts: 8
Joined: 25 Mar 2013 13:27

Re: SOLVED: Using a batch file to find and rename files.

#11 Post by osburn383 » 26 Mar 2013 09:10

Ok the files are there. I was overlooking them.

Everything works great. :D

Thanks again for the help.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: SOLVED: Using a batch file to find and rename files.

#12 Post by foxidrive » 26 Mar 2013 09:14

That's good to hear. Cheers.

osburn383
Posts: 8
Joined: 25 Mar 2013 13:27

Re: SOLVED: Using a batch file to find and rename files.

#13 Post by osburn383 » 26 Mar 2013 09:23

Well almost great lol.

There are image and pdf files that do not need changing that i forgot are in a folder called Raster.

Instead of CAD it is called Raster.
L:\Michael\Organized Updated Drawings\32\Raster\A\32-A-009

Is there a way to exclude pdf, jpg, tiff and png from being changed?

I wasn’t thinking about how the batch file would affect those files.

Maybe exclude the Raster file from being accessed?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Using a batch file to find and rename files.

#14 Post by foxidrive » 26 Mar 2013 12:48

This will exclude every folder from raster and below it.

Code: Select all

@echo off
del renfiles.bat.txt 2>nul
dir /a-d /b /s "L:\Michael\Organized Updated Drawings\" | find /v /i "\raster" >file.tmp
for /f "delims=" %%a in (file.tmp) do >>renfiles.bat.txt echo ren "%%a" "%%~na.DGN"
del file.tmp

osburn383
Posts: 8
Joined: 25 Mar 2013 13:27

Re: Using a batch file to find and rename files.

#15 Post by osburn383 » 26 Mar 2013 13:08

Ok thats got every issue fixed.

Thanks!

Post Reply