Remove last seven characters from multiple filenames?

jdcrutch

New member
Local time
4:47 AM
Messages
8
Hello.

I have a bunch of documents in a data base, all associated with TIFF images, and all having unique DOCIDs. When I batch-print several of the TIFFs to PDFs, the stupid program, instead of just naming them by their DOCIDs, appends a seven-digit serial number to the DOCID, thus:

ABCD0000789 --> ABCD00007891234567.PDF
I want to delete those last seven digits before the dot.

I know there are free utilities that make this stuff easy, but I'm at work, where I'm not allowed to install programs; so I have to use native DOS or Windows 7 functions. I'm sure it can be done quickly and easily with the REN command in a DOS window, but I don't know how to identify the last seven digits for REN and tell it to delete them.

Unfortunately, what comes before the last seven digits is variable--it's always some letters followed by some numerals, but the number of each can vary, there might be a hyphen or a space among the letters, and there might be a space between the letters and the numerals; so I can't just tell DOS to delete everything after the first n digits, which I gather would be easier. (I've found several examples of scripts for removing the first so-many digits, but I can't figure out how to adapt those to solve my problem.)


Thanks for any help.

Regards,

Jim Crutchfield
Long Island City, NY
 

My Computer My Computer

At a glance

Windows 7 x64
OS
Windows 7 x64
Hi,

I too wouldn't mind knowing how to do this if it's possible.
I seem to have gotten as far as you.. that being i can remove x digits from the beginning but not from the end :cry:

I will see if i can get someone that knows :D

Regards,
 

My Computer My Computer

At a glance

Windows 8.1 Pro x64Intel Core i5-2500K @ 3.30GHz - S11558GB Corsair DDR3 XMS3, PC3-12800NVIDIA GeForce GTX 650
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
ReNamer « Products « den4b.com

Been using it for years. Pay attention to the preview to make sure you've got it the way you want it. :)

EDIT: Oops. Didn't catch the part about "Not installing programs". Sorry. :o
 

My Computer My Computer

At a glance

Main - Windows 7 Pro SP1 64-Bit; 2nd - Window...Main - Core i7 2600K; 2nd - Core i7 920Main - 16GB Corsair Vengeance; 2nd - 12GB Cor...Main - XFX Radeon 6870 1GB; 2nd - XFX Radeon ...
Computer Manufacturer/Model Number
Self
OS
Main - Windows 7 Pro SP1 64-Bit; 2nd - Windows Server 2008 R2
CPU
Main - Core i7 2600K; 2nd - Core i7 920
Motherboard
Main - Asus P8Z68-V Pro/Gen3; 2nd - Gigabyte GA-EX58-UDR3
Memory
Main - 16GB Corsair Vengeance; 2nd - 12GB Corsair Vengeance
Graphics Card(s)
Main - XFX Radeon 6870 1GB; 2nd - XFX Radeon 4870 1GB
Sound Card
Both: Onboard Realtek Azalia
Monitor(s) Displays
Main - Hann 25" + I-INC 25" + Acer 23"; 2nd - Upgrading Soon
Screen Resolution
Main - 1920x1080 (All Three Monitors); 2nd - Upgrading Soon
Hard Drives
Main - (1) Crucial M4 128GB (Boot)
Main - (1) Seagate 2TB 64MB Cache (Data)
Main - (1) Seagate 2TB 64MB Cache (Data Backup)
2nd - (1) Intel X25-M SSD 80GB (Boot)
2nd - (3) Seagate 1TB 32MB Cache (Data Backup)
2nd - (1) Seagate 320GB (Because)
PSU
Main - OCZ 600W Modular; 2nd - OCZ 600W
Case
Main - Thermaltake Element G; 2nd - NZXT something or other
Cooling
Main - Corsair H80; 2nd - Prolimatech Megahalems
Keyboard
Main - Razer Reclusa; 2nd - Old MS Keyboard
Mouse
Main - Logitech MX Revolution; 2nd - Old MS Mouse
Internet Speed
20Mbps Time-Warner Cable
Just so I'm not a total drag, can you link to one of the scripts you've tried so far? Though I wouldn't consider myself a "Programmer", I've had a few programming assignments similar to this stuff. Maybe I can make up for being a gun-jumper. ;)
 

My Computer My Computer

At a glance

Main - Windows 7 Pro SP1 64-Bit; 2nd - Window...Main - Core i7 2600K; 2nd - Core i7 920Main - 16GB Corsair Vengeance; 2nd - 12GB Cor...Main - XFX Radeon 6870 1GB; 2nd - XFX Radeon ...
Computer Manufacturer/Model Number
Self
OS
Main - Windows 7 Pro SP1 64-Bit; 2nd - Windows Server 2008 R2
CPU
Main - Core i7 2600K; 2nd - Core i7 920
Motherboard
Main - Asus P8Z68-V Pro/Gen3; 2nd - Gigabyte GA-EX58-UDR3
Memory
Main - 16GB Corsair Vengeance; 2nd - 12GB Corsair Vengeance
Graphics Card(s)
Main - XFX Radeon 6870 1GB; 2nd - XFX Radeon 4870 1GB
Sound Card
Both: Onboard Realtek Azalia
Monitor(s) Displays
Main - Hann 25" + I-INC 25" + Acer 23"; 2nd - Upgrading Soon
Screen Resolution
Main - 1920x1080 (All Three Monitors); 2nd - Upgrading Soon
Hard Drives
Main - (1) Crucial M4 128GB (Boot)
Main - (1) Seagate 2TB 64MB Cache (Data)
Main - (1) Seagate 2TB 64MB Cache (Data Backup)
2nd - (1) Intel X25-M SSD 80GB (Boot)
2nd - (3) Seagate 1TB 32MB Cache (Data Backup)
2nd - (1) Seagate 320GB (Because)
PSU
Main - OCZ 600W Modular; 2nd - OCZ 600W
Case
Main - Thermaltake Element G; 2nd - NZXT something or other
Cooling
Main - Corsair H80; 2nd - Prolimatech Megahalems
Keyboard
Main - Razer Reclusa; 2nd - Old MS Keyboard
Mouse
Main - Logitech MX Revolution; 2nd - Old MS Mouse
Internet Speed
20Mbps Time-Warner Cable
I have been running straight in the dos window while testing hence only 1 % and only testing on 1 file at the moment

Code:
for %i in (*.txt) do (set fName=%i)
then
Code:
ren %fName% %fName:~7%

That just removes the first 7 digits... still working on the last digits.
 

My Computer My Computer

At a glance

Windows 8.1 Pro x64Intel Core i5-2500K @ 3.30GHz - S11558GB Corsair DDR3 XMS3, PC3-12800NVIDIA GeForce GTX 650
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
based on my example above i think i have done it!!

From within the cmd window i have changed the directory to where i have put some test .txt files and the ran the 2 commands below.

Code:
for %i in (*.txt) do (set fName=%i)
ren %fName% %fName:~0,-11%.txt
 

My Computer My Computer

At a glance

Windows 8.1 Pro x64Intel Core i5-2500K @ 3.30GHz - S11558GB Corsair DDR3 XMS3, PC3-12800NVIDIA GeForce GTX 650
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
based on my example above i think i have done it!!

Code:
for %i in (*.txt) do (set fName=%i)
ren %fName% %fName:~0,-11%.txt

Just need to update the file extension to .pdf and to put it in some sort of loop to do multiple files?
 

My Computer My Computer

At a glance

Windows 8.1 Pro x64Intel Core i5-2500K @ 3.30GHz - S11558GB Corsair DDR3 XMS3, PC3-12800NVIDIA GeForce GTX 650
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
Thanks for the help!

I'm working with only one file at the moment, and I copied JDobbsy's code exactly, except that I put in ".pdf" for ".txt":

Code:
for %%i in (*.pdf) do (set fName=%i)
ren %fName% %fName:~0,-11%.pdf

Unfortunately, when I try that, I get,
C:\Temp\test>i) was unexpected at this time.
C:\Temp\test>for i)

The help file for "FOR" says,
To use the FOR command in a batch program, specify %%variable instead of %variable.
so I tried
Code:
for %%i in (*.pdf) do (set fName=%i)
ren %fName% %fName:~0,-11%.pdf

which results in
C:\Temp\test>for %i in (*.pdf) do (set fName=i )
C:\Temp\test>(set fName=i )
C:\Temp\test>ren i .pdf
The system cannot find the file specified.

I'm probably just showing my ignorance here--or maybe my senility: it's been twenty years since I tried to write a DOS batch file, and I've completely forgotten the language. I'm probably leaving out standard code that you guys take for granted.

Meanwhile, I've found the following on DOStips.com, which looks like it might be something in the right direction:

Code:
:rTrim string char max -- strips white spaces (or other characters) from the end of a string
::                     -- string [in,out] - string variable to be trimmed
::                     -- char   [in,opt] - character to be trimmed, default is space
::                     -- max    [in,opt] - maximum number of characters to be trimmed from the end, default is 32
:$created 20060101 :$changed 20080219 :$categories StringManipulation
:$source http://www.dostips.com
SETLOCAL ENABLEDELAYEDEXPANSION
call set string=%%%~1%%
set char=%~2
set max=%~3
if "%char%"=="" set char= &rem one space
if "%max%"=="" set max=32
for /l %%a in (1,1,%max%) do if "!string:~-1!"=="%char%" set string=!string:~0,-1!
( ENDLOCAL & REM RETURN VALUES
    IF "%~1" NEQ "" SET %~1=%string%
)
EXIT /b

But I can't really read it well enough to know. I don't think it requires the string to have any particular number of characters before the ones we want to trim.

I suspect that if we set "%char%" to * (i.e., any character) and set "%max%" to equal seven (or 11 if we can't define the file suffix out of our string), it might work; but we'd need to preserve (or restore) the file suffix.

I also don't see how the string is defined in the first place (maybe that "call" function at the beginning?); and I'm not sure how to make a loop in a DOS batch file, though that shouldn't be hard to find out.

I'll give it a try, but I'll have to rely on you guys to make it work. ;0)

Thanks again!

Regards,

Jim Crutchfield
 

My Computer My Computer

At a glance

Windows 7 x64
OS
Windows 7 x64
Hi Jim,

I will look further into getting it to work in a loop for multiple files tomorrow however the code i posted was entered directly into the command prompt.

In order to use that in a batch file you need double %% which you did pick up on:

so I tried
Code:
for %%i in (*.pdf) do (set fName=%%i)
ren %fName% %fName:~0,-11%.pdf

however you forgot the second %i

Try this:
Code:
for %%i in (*.pdf) do (set fName=%i)
ren %fName% %fName:~0,-11%.pdf
This will only work for 1 PDF though.

As i said, i will work a little more on this to try and create the batch file to do multiple file tomorrow.
As i know this command works, i know it will do the trick, the issue getting it to work for multiple file is getting the for /f loop to work (not really done a lot with for loops before)

Regards,
JDobbsy1987
 

My Computer My Computer

At a glance

Windows 8.1 Pro x64Intel Core i5-2500K @ 3.30GHz - S11558GB Corsair DDR3 XMS3, PC3-12800NVIDIA GeForce GTX 650
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
Aha! Thanks, JDobbsy! Adding another % let the command run, but I hove up against another problem: many of my filenames have spaces in them, which make REN return a syntax error. By trial and error, I figured out how to put the fName variable in quotation marks:

Code:
for %%i in (*.pdf) do (set fName="%%i")

and that worked like a charm, except that

Code:
ren %fName% %fName:~0,-11%.pdf

was only lopping off the last six digits. I don't know what the ~0,-11 arguments mean (assuming they're arguments), but I took a wild stab and changed -11 to -12. Now here's what I get:

C:\Temp\test>renpdf.bat
C:\Temp\test>for %i in (*.pdf) do (set fName="%i")
C:\Temp\test>(set fName="EY 000000302768049.pdf")
C:\Temp\test>ren "EY 000000302768049.pdf" "EY 00000030.pdf"

which is exactly what I want. I don't know how it works, but it works. Thanks again, JDobbsy1987! Now for the loop!

Edit: a little research tells me that the ~0,-12 bit is a modifier that strips the last n characters (in this case, n=12) from a string. I guess I had to add a character to JDobbsy1987's -11 in order to account for the quotation mark I'd added, though I'm not sure why that doesn't let the space cause problems again. At any rate, it seems to work.
 

My Computer My Computer

At a glance

Windows 7 x64
OS
Windows 7 x64
Hey JDobbsy1987, kind of sloppy/clunky, but instead of renaming with the same extension go with something different, that way you could run it on a folder full of files. When it's done you run code to correct the extension.
 

My Computer My Computer

At a glance

Windows 7 Ultimate x64
OS
Windows 7 Ultimate x64
Hey JDobbsy1987, kind of sloppy/clunky

It is a little clunky at the moment but as i said in earlier posts, these commands were just to get the rename command to work correctly within the command window (not a batch file), now i have that all i need to do is create a new command with a for loop that will replace the previous commands mentioned in this thread. once i have done that it will not be clunky... just a standard batch file.


instead of renaming with the same extension go with something different, that way you could run it on a folder full of files. When it's done you run code to correct the extension.
Why run a 2nd command to correct the file extension when the first command can do it at the same time, we know that files that need renaming are PDF's?

That is not the issue, this issue is just putting the rename command in a loop... nothing to do with the file extension.

I have nearly got the for loop working by the way
 

My Computer My Computer

At a glance

Windows 8.1 Pro x64Intel Core i5-2500K @ 3.30GHz - S11558GB Corsair DDR3 XMS3, PC3-12800NVIDIA GeForce GTX 650
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
was only lopping off the last six digits. I don't know what the ~0,-11 arguments mean (assuming they're arguments), but I took a wild stab and changed -11 to -12. Now here's what I get:

C:\Temp\test>renpdf.bat
C:\Temp\test>for %i in (*.pdf) do (set fName="%i")
C:\Temp\test>(set fName="EY 000000302768049.pdf")
C:\Temp\test>ren "EY 000000302768049.pdf" "EY 00000030.pdf"

which is exactly what I want. I don't know how it works, but it works. Thanks again, JDobbsy1987! Now for the loop!

Edit: a little research tells me that the ~0,-12 bit is a modifier that strips the last n characters (in this case, n=12) from a string. I guess I had to add a character to JDobbsy1987's -11 in order to account for the quotation mark I'd added, though I'm not sure why that doesn't let the space cause problems again. At any rate, it seems to work.

I'm glad this is what you are after, I nearly have the loop working, hopefully i will have this back to you by tomorrow evening (well this evening as it's past midnight :D)

You are correct about the below code
Code:
ren %fName% %fName:~0,-11%.txt

~0 = Remove the first n letters (we don't want to remove any hence 0)
,-11 = Remove the last n letters

Regards,
JDobbsy1987
 

My Computer My Computer

At a glance

Windows 8.1 Pro x64Intel Core i5-2500K @ 3.30GHz - S11558GB Corsair DDR3 XMS3, PC3-12800NVIDIA GeForce GTX 650
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
Hey JDobbsy1987,

Sorry I wasn't clear, I meant my addition would be sloppy/clunky, not yours.

Everytime I've gone and looked at batch files I've written over the years, I think "you know, I really could wipe out a few lines here and there and be more efficient just by modifying a couple other lines".
 

My Computer My Computer

At a glance

Windows 7 Ultimate x64
OS
Windows 7 Ultimate x64
Hey JDobbsy1987,

Sorry I wasn't clear, I meant my addition would be sloppy/clunky, not yours.

Everytime I've gone and looked at batch files I've written over the years, I think "you know, I really could wipe out a few lines here and there and be more efficient just by modifying a couple other lines".

Ah, I misunderstood sorry :D, i do find that i end up re-writing old batch files reducing them from 20 lines down to 10 as i pick up more over time.
 

My Computer My Computer

At a glance

Windows 8.1 Pro x64Intel Core i5-2500K @ 3.30GHz - S11558GB Corsair DDR3 XMS3, PC3-12800NVIDIA GeForce GTX 650
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
I thought you were having problems with a working, but never ending command. I was thinking you were looking for a way to stop the loop at the right moment.
 

My Computer My Computer

At a glance

Windows 7 Ultimate x64
OS
Windows 7 Ultimate x64
OK Jim...

I have now got the script to work, 2 batch files are required for it.
All the .PDF's will need to be put in a folder for it to work (obviously if you can change the script to look in different folders then go for it :D

Please put a copy of a few PDF's into a folder to test the following:

First you need to create the 2 batch files:

Make batch file called "RunMe.bat" with the following code:
Code:
dir /b | find "pdf" /i > temp.log
 set tempvar=
 for /f "tokens=1-2 delims=." /f %%A in (temp.log) do (
 rename_file.bat %%A %%B
 )

 del temp.log

Now create a batch file called "ReName_File.bat" with the following code:
Code:
set fName=%1
 ren %fName%.%2 %fName:~0,-7%.%2

Put the 2 batch files in the folder with the test pdf's and then double click the RunMe.bat

It may take a second but all the files should now have the last 7 digits removed?

Please advise how you get on.
Sorry it has taken so long to get to the bottom of it :D

Regards,
JDobbsy1987
 

My Computer My Computer

At a glance

Windows 8.1 Pro x64Intel Core i5-2500K @ 3.30GHz - S11558GB Corsair DDR3 XMS3, PC3-12800NVIDIA GeForce GTX 650
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
Brilliant, JDobbsy1987! I really appreciate your putting in all this time to help me.

Just for my education, and not trying to be a know-it-all, but it seems strange to have to run two separate batch files, rather than one with function calls. Can you explain why the former is better? (Easier counts as better in my book, even if it's less elegant, since you're doing this out of the goodness of your heart, after all.)

If you have the further time and inclination to walk me through these scripts, step by step, so I'll understand how they work, I'll be even more grateful--because I realize it wouldn't be all that much trouble for me to educate myself about all this, and you've already done a lot. It's not clear to me, e.g., since you don't have an "IF" or a "FOREACH" (which I don't think DOS recognizes), how the script knows to stop running after it's renamed each file once, and not keep going until all the files have names of less than seven characters. So if you feel like educating me as well as helping me out, please do.

I do like the way you got around having to restore the file suffix, by the way, and I think I even understand how you did it. I knew there must be a way.

I'll give these a try when I get home tonight (don't want to try them at work yet, because the firm has very strict IT policies, and I want to be able to say that I've tried them at home, and they work, when I ask permission to run them at the office).

Thanks again, JDobbsy1987. You're a champ.

Regards,

Jim Crutchfield
 

My Computer My Computer

At a glance

Windows 7 x64
OS
Windows 7 x64
Hi Jim,

It's not a problem, the reason i have 2 batch files is it's to do with how loops deal with variables and the order the commands are run in the stack (it may be possible to get it to run in a single batch file but much easier {for me} to get it split over 2 although I'm not actually sure it is possible to do this is a single command/batch file due to the rename variable).

You don't need to specify the file extension in the script as the for loop uses a delimiting character to split it into two variables (%%A and %%B) with A being the file name, and B being the extension.

Both of those are then loaded into rename_file.bat as %1 and %2 respectively. It works this way because rename_file.bat is called for each loop, and when it finished its two lines, it closes, and therefore removes the fName variable so it can be reused by the next loop.

I hope his helps understand it a little more.

Regards,
JDobbsy1987
 

My Computer My Computer

At a glance

Windows 8.1 Pro x64Intel Core i5-2500K @ 3.30GHz - S11558GB Corsair DDR3 XMS3, PC3-12800NVIDIA GeForce GTX 650
Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self Built
OS
Windows 8.1 Pro x64
CPU
Intel Core i5-2500K @ 3.30GHz - S1155
Motherboard
Asus P8P67 LE Rev3, Intel P67, S115
Memory
8GB Corsair DDR3 XMS3, PC3-12800
Graphics Card(s)
NVIDIA GeForce GTX 650
Sound Card
On-Board
Monitor(s) Displays
3 x 24" {Extended Display}
Screen Resolution
1920 x 1080
Hard Drives
300GB Seagate Barracuda 7200
PSU
550W Coolermaster GX550
Case
Silverstone Precision PS04B
Cooling
Stock
Keyboard
Logitech K120
Mouse
World of Warcraft Cataclysm MMO Gaming Mouse
Internet Speed
80 MB
Antivirus
MSE / Windows Defender
Browser
Chrome
That helps a lot. Can't wait to try 'em out. I'd thank you again, but I might be starting to sound a bit effusive. ;0)
 

My Computer My Computer

At a glance

Windows 7 x64
OS
Windows 7 x64
Back
Top