Solved

VB Script ,Shell Scripting ,Windows Batch Scripting

Posted on 2013-12-21
9
509 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 69

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

778 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