Solved

VB Script ,Shell Scripting ,Windows Batch Scripting

Posted on 2013-12-21
9
448 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 68

Assisted Solution

by:Qlemo
Qlemo earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:VN-PC view
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Steve & Qlemo

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

Expert Comment

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

Steve
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now