Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB Script ,Shell Scripting ,Windows Batch Scripting

Posted on 2013-12-21
9
Medium Priority
?
517 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 71

Assisted Solution

by:Qlemo
Qlemo earned 1000 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 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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 …
Suggested Courses

704 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