Link to home
Start Free TrialLog in
Avatar of WellingtonIS
WellingtonIS

asked on

bat file command

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?
Avatar of ThorinO
ThorinO
Flag of United States of America image

Avatar of Lee W, MVP
if not exist c:\icons md c:\icons
Avatar of NotVeryFat
NotVeryFat

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
Avatar of WellingtonIS

ASKER

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

if not exist c:\icons MD c:\icons
Will try thanks!
why are you not just putting this folder in the allusers profile under documents and settings?
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
> 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
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
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.
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...
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).
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.
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.
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.
Yes I know how to create screen shots but because I'm using another program, it's hard to tell what error are occuring.
That's the screen shot when I ran via cmd.  the folder isn't created.
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?
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.
the command returns no output ... as you can see in the attached User generated image
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!
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.
ASKER CERTIFIED SOLUTION
Avatar of Lionel MM
Lionel MM
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.
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?