Solved

bat file command

Posted on 2011-02-14
28
445 Views
Last Modified: 2012-06-21
I have a bat file to install certain icons on the desktop.  It starts off with
mkdir c:\icons

I want to be able to add icons to this folder however, I want to be able to tell it if the folder exists copy the icons if not then create it.

How can I do this?
0
Comment
Question by:WellingtonIS
  • 14
  • 7
  • 2
  • +4
28 Comments
 
LVL 10

Expert Comment

by:ThorinO
ID: 34889764
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 34889798
if not exist c:\icons md c:\icons
0
 
LVL 5

Expert Comment

by:NotVeryFat
ID: 34889802
I'd have the icons on a server share to copy, then something along the lines of:

if exist %userprofile%\Desktop\Icon1.lnk then goto end
if not exist %userprofile%\Desktop\Icon1.lnk then goto copy_icons

:copy_icons
xcopy "\\SERVER\Share\Icon1.lnk" "%userprofile%\dekstop" /C /Q /Y
xcopy "\\SERVER\Share\Icon2.lnk" "%userprofile%\dekstop" /C /Q /Y

:end
exit
0
 

Author Comment

by:WellingtonIS
ID: 34889807
OK then so I can check by saying
if exists c:\icons then copy... how do I say if it's not there MKDIR c:\icons
0
 
LVL 5

Expert Comment

by:_-MYFOX-_
ID: 34889817

if not exist c:\icons MD c:\icons
0
 

Author Comment

by:WellingtonIS
ID: 34889840
Will try thanks!
0
 
LVL 3

Expert Comment

by:rxdeath
ID: 34890833
why are you not just putting this folder in the allusers profile under documents and settings?
0
 

Author Comment

by:WellingtonIS
ID: 34890940
OK it's not creating the folder:

I have
if exist c:\icons then go to copy_icons
if not exist c:\icons MD c:\icons

it's not creating the folder????  I also tried mkdir c:\icons
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 34890982
> if exist c:\icons then go to copy_icons

Batch doesn't understand Then and "go to" should be "goto".  You also don't appear to have a label "copy_icons" anywhere.

The above line (or a working version of it) should not be necessary in conjunction with the If not exist c:\icons md c:\icons line - Are you sure you have permission to the C: drive?  How are you testing this?  Can you post a screen shot of what happens when the file is run (do NOT double click on it... or if you do, make sure the alst line (right now, for debugging purposes) is Pause
0
 

Author Comment

by:WellingtonIS
ID: 34891082
OK you're correct the entire thing isn't working... Is there any way to do this.  I want to have the bat file check to see if there's a folder  called c:\icons. and if not create it, if yes just copy the icons in to that folder...

I
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 34891113
Absolutely... but so far, we don't have a complete idea (read: complete script you're attempting to use) to understand what you want to do.  You also aren't posting the requested screen shots which would show EXACT error messages.  And you aren't doing anything to indicate what, exactly you are using as code other than, maybe, new lines.

I'm sure we're all happy to help, but you need to be more forthcoming and show better details of what you're doing/getting.
0
 

Author Comment

by:WellingtonIS
ID: 34891130
sorry I give you the entire thing.  I have the copy_icons too...
if exist c:\icons then go to  copy_icons
if not exist c:\icons MKDIR c:\icons

  :copy_icons
copy...
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 34891148
That doesn't look like the entire thing.

copy... is not a command.

Let me put this another way - post the ENTIRE - ALL - the COMPLETE batch file - open it in notepad, go to the Edit menu, select "Select All" then select "Copy", then come back to the question and right click the comment body window and select paste.

(You also haven't edited the lines I told you clearly do not work).
0
 

Author Comment

by:WellingtonIS
ID: 34891167
if exist c:\icons then got to copy_icons
if not exist c:\icons MkDir "c:\icons"
 :copy_Icons
copy "Forms1.ico" "C:\Icons" /y
copy "forms-on-demand.url" "C:\Icons" /y
copy "c:\icons\forms-on-demand.url" "%AllUsersProfile%\Desktop" /y

could use xcopy too, copy did work.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 34891192
Thank you.

You have this:
if exist c:\icons then got to copy_icons
if not exist c:\icons MkDir "c:\icons"
 :copy_Icons
copy "Forms1.ico" "C:\Icons" /y
copy "forms-on-demand.url" "C:\Icons" /y
copy "c:\icons\forms-on-demand.url" "%AllUsersProfile%\Desktop" /y

Open in new window


It should be:
if not exist c:\icons MkDir "c:\icons"
copy "Forms1.ico" "C:\Icons" /y
copy "forms-on-demand.url" "C:\Icons" /y
copy "c:\icons\forms-on-demand.url" "%AllUsersProfile%\Desktop" /y

Open in new window


If it doesn't work, take a screen shot (do you know how to take a screen shot?) and post it here (do you know how to post it here?)

If the above is your exact code, then the screen shot should provide all the information necessary to debug this.
0
 

Author Comment

by:WellingtonIS
ID: 34891220
One more thing... This is comming from another program called DSM.  the bat file only has to specify where the stuff is.  I don't have give it shares, it's understood in the DSM.
0
 

Author Comment

by:WellingtonIS
ID: 34891253
Yes I know how to create screen shots but because I'm using another program, it's hard to tell what error are occuring.
0
 

Author Comment

by:WellingtonIS
ID: 34891283
0
 

Author Comment

by:WellingtonIS
ID: 34891288
That's the screen shot when I ran via cmd.  the folder isn't created.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 34891386
If you use ALT+PRT SCRN you get JUST the active Window - no need to cut and paste a portion of it.

There are no error messages returned, implying that the command completed successfully.  Are you saying when you look for the folder "icons in the root of C:, you still don't see it after the batch file has run?
0
 

Author Comment

by:WellingtonIS
ID: 34891659
I got it to work...
IF NOT EXIST C:\ICON MKDIR C:\ICON

it didn't like icons why I don't know.  My only issue is getting the stupid Icon url to see the correct picture.
0
 
LVL 5

Expert Comment

by:_-MYFOX-_
ID: 34892329
the command returns no output ... as you can see in the attached cmd example
0
 
LVL 24

Expert Comment

by:lionelmm
ID: 34896767
What version of Windows are you using, and what type of user is this--administrator, power user, what? And can you test this for me--use Windows Explorer and use it to make the directory Icons and let me know what happens when you do--thanks!
0
 

Author Comment

by:WellingtonIS
ID: 34896800
I'm using XP pro and logged in with a user name that has no rights at all.  I'm running this bat file via a program called DSM.  I was able to get the directory icon to create but not Icons.
0
 
LVL 24

Accepted Solution

by:
lionelmm earned 500 total points
ID: 34896856
Well I ran both
IF NOT EXIST C:\ICON MKDIR C:\ICON and
IF NOT EXIST C:\ICONS MKDIR C:\ICONS and both were created so there has to be something more that is preventing it from working
0
 

Author Comment

by:WellingtonIS
ID: 34896927
Perhaps.  I'm still looking into it.  I will get back to you as soon as I figure out why it won't create ICONS
0
 

Author Comment

by:WellingtonIS
ID: 34898234
i've tried this on another machine and it did work.  So it did work. I'm using it with c:\icon.  thanks for the help.
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 34898358
That really should have either been awarded to Thorin0 or split amongst us... I spent a lot of time trying to help you and apparently my help was worth nothing?
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

11 Experts available now in Live!

Get 1:1 Help Now