Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB Script ,Shell Scripting ,Windows Batch Scripting

Posted on 2013-12-21
9
Medium Priority
?
523 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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

885 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