Solved

VB Script ,Shell Scripting ,Windows Batch Scripting

Posted on 2013-12-21
9
513 Views
Last Modified: 2013-12-21
Hi experts

I have about 300 folders, inside each folder has few mix files exe / pdf/ and some  file with name BUT NO EXTENSiON . I want to rename those files without NO EXTENSION to doc file
is there batch file can do this task
thanks in advance

this is what did on mine batch but it seemed not working
@ECHO OFF
PUSHD .
FOR /R %%d IN (.) DO (
    cd "%%d"
    IF EXIST *.* (
       REN *.* *.jpg
    )
)
POPD
0
Comment
Question by:VN-PC view
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 250 total points
ID: 39733666
Your code and the description are not fitting together that much, but from what I read:
@ECHO OFF
for /F %%F in ('dir /s/b /a:-d *.') do ren "%%~F" *.doc

Open in new window

0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 250 total points
ID: 39733673
That Qlemo too quick again!   Aside from the fact I was about to use %%a the same... you should be good to go except I think you will also need "tokens=*" in case of filenames or dirs with spaces in:

@ECHO OFF
cd /d "c:\start dir"
for /F "tokens=*" %%F in ('dir /s/b /a:-d *.') do ren "%%~F" *.doc

Open in new window


To explain (not that Qlemo wouldn't and points to Qlemo of course.... the dir listing is a bare directory listing of all filenames that match *. (no extension) through all subdirectories from the current one down, the /a:-d only shows files, not dirs, and then for loop goes through each in turn running the for command.

Steve
0
 

Author Comment

by:VN-PC view
ID: 39733823
hi  Steve

your code is working , can i ask you why it tried ran through C drive.

for instance the folder\files is on c:\new . is there a way when run your bat it just go to c:\new and that's it. i saw it running through program files/windows, look like complete c drive
secondly, there showing something file too long name so if my files has too long name, will it work?
many thanks in advance
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 39733837
It should work down from the current directory, you can change to that first, or use the line cd /d "c:\new" to move there first.

Alternatively you can add the path as part of the dir, i.e.

@ECHO OFF
cd /d "c:\new"
for /F "tokens=*" %%F in ('dir /s/b /a:-d *.') do ren "%%~F" *.doc

Open in new window


or

@ECHO OFF
for /F "tokens=*" %%F in ('dir /s/b /a:-d c:\new\*.') do ren "%%~F" *.doc

Open in new window


Again I only added "tokens=*" to what Qlemo wrote for you though.

Unless you have very long paths it shouldn't be an issue.

Steve
0
 

Author Comment

by:VN-PC view
ID: 39733849
steve

cd /d "c:\start dir" ? do  i need to change it to cd /d "c:\new dir"

 because the folder is on c:\new

thanks in advance
0
 

Author Comment

by:VN-PC view
ID: 39733885
steve and Qlemo


would you guy look at the attach file, my question is it tried to look through my c drive not just folder i wanted it to do c:\new . i did changed you statement to below

@ECHO OFF
cd /d "c:\new dir"
for /F "tokens=*" %%F in ('dir /s/b /a:-d *.') do ren "%%~F" *.doc

i am bit of nervous it i ran it on the file server, it might rename file any files with no extension to DOC, it might an issue , need you both input would be appreciate..
Capture.PNG
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39733907
Sorry "c:\start dir" was an example as in a directory to start from called "c:\start dir"

Use cd /d "c:\new" if that is where you need to start, or safer use my second example with c:\new as part of the dir.

If you use this it will show you the commands it would run but not run them.

Remove the word ECHO in capitals to make it do it.

@echo off
for /F "tokens=*" %%F in ('dir /s/b /a:-d c:\new\*.') do ECHO ren "%%~F" *.doc

Open in new window


Steve
0
 

Author Comment

by:VN-PC view
ID: 39733915
Steve & Qlemo

you guy awesome it worked. thank a millions guys
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39733920
No problem, was only passing pc when it popped up at the right moment..

Steve
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question