Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Batchfile to make shortcuts - possible? (XP Pro SP2)

    Not sure if this is the correct forum but I'm wondering if it is possible to make a batch file that will create shortcuts for all the files in a specified folder inside the same folder. I know how to do this by hand but I'd like to be able to do it automatically.

    Thanks,

    Chris (Hunt)

  2. #2
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batchfile to make shortcuts - possible? (XP Pr

    There is a utility called Shortcut which may get you what you want - but I'm mystified as to why you would want a shortcut to a file in the same folder!

  3. #3
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Batchfile to make shortcuts - possible? (XP Pr

    You could try, in a Command Prompt window, changing to the directory you want then doing running Leif's (well, Marty List's!) SHORTCUT for each file.<pre>CD <path>required-directory
    FOR %a IN (*.*) DO SHORTCUT /t:"%a" /f:"Shortcut to file %a" /a:c <any other parameters>
    </pre>

    How practical it will be to do it this way depends on whether all parameters other than the three I've indicated stay the same...

    Test it on a small directory first - it works for me!

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  4. #4
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batchfile to make shortcuts - possible? (XP Pr

    Thanks for the replies. I tried using the command prompt as John suggest but got an error message (87, I think). Even if I could get it to work from the command prompt I'm not sure how useful that would be as it is quicker for me to navigate using Windows Explorer and do a select all, rightclick and make shortcut than type in all the parameters into the command prompt. My idea was to have a batch file that would run when the computer switched off that would make a shortcut for every file saved into my "working folder" during the day and then move the actual files to their appropriate directories. Guess I'll have to do it by hand.

    Thanks again,

    Chris

  5. #5
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Batchfile to make shortcuts - possible? (XP Pr

    <hr>My idea was to have a batch file that would run when the computer switched off that would make a shortcut for every file saved into my "working folder" during the day and then move the actual files to their appropriate directories.<hr>
    Since the shortcuts contain the absolute path to the file when the shortcut was made, then moving the files to another directory will make the shortcuts fail, surely?

    John

    PS If you wanted to make my Command Prompt command into a BATch file, you would just have to replace every single % by a double % (that is, %a -> %%a)
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  6. #6
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batchfile to make shortcuts - possible? (XP Pr

    Thanks John, my knowledge about batch files is limited. I tried the following but it didn't work.

    ------------------------
    path c:test

    FOR %%a IN (*.*) DO SHORTCUT /t:"%%a" /f:"Shortcut to file %%a" /a:c
    ------------------------

    I have a suspicion that shortcut.exe is not being accessed as I have ProcessGuard installed and currently that is set to flash a pop-up when shortcut.exe tries to run. I'm not getting any pop-up. I have a copy of shortcut.exe in my system32 folder. What am I doing wrong?

    Chris

  7. #7
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Batchfile to make shortcuts - possible? (XP Pr

    I'm no batch file wizard myself, but I think I know enough to tell you that your first line shouldn't use the "PATH" command. That sets the environment variable "PATH", which is a list of directories that Windows (formerly DOS) will search for executable files if the command at the start of any batch file line isn't an internal command and doesn't otherwise have a path specified.

    The reference to (*.*) in the line John provided is a reference to all the files in whatever the default directory is when the line is run. That's why John preceded that line with a "CD ..." line (to change the default directory to the directory where you want to create the shortcuts).

    So, in other words, the first line of your batch file should be<pre>CD C:TEST</pre>

    rather than PATH C:TEST.

    You may want to try to figure out what directory was the default directory when you were running your version of the batch file, because I suspect it may have a bunch of shortcuts you didn't intend to create.

  8. #8
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batchfile to make shortcuts - possible? (XP Pr

    Thanks for the reply, I've searched my hardrive for newly made shortcuts but haven't found any. After making the change you suggested shortcut.exe did run (I got a ProcessGuard warning) but no shortcuts were created.

    Chris

  9. #9
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Batchfile to make shortcuts - possible? (XP Pr

    While we await the Return of the Bobbing Badger, you might want to try adding the path to the SHORTCUT t: parameter -- i.e., add C:TEST between the open-quote and the first percent sign.

    (I tried typing what I meant, but the board "translates" my percent-sign-followed-by-"a", messing up my message.)

    UPDATE: Now I remember: You put square brackets around % to avoid unwanted "translations." So here's the replacement line I'm proposing:<pre>FOR %%a IN (*.*) DO SHORTCUT /t:"C:TEST%%a" /f:"Shortcut to file %%a" /a:c
    </pre>


  10. #10
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batchfile to make shortcuts - possible? (XP Pr

    Thanks for sticking with this. Adding C:test definitely helped in that two files were created. But they didn't seem to be shortcuts (no shortcut icon) but actual empty files. As an experiment I tried removing the "shortcut to file" part leaving me with /f: "%%a". This actually overwrote my test Coreldraw files with empty Coreldraw files of the same name. Looks like I need to be very careful with this before letting loose on actual files.

    Chris

    Edited: GOT IT! I needed to add the .lnk extension:

    /f:"%%a.lnk"

    Produces a working link!

  11. #11
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batchfile to make shortcuts - possible? (XP Pr

    I've almost got it working - that is I can create shortcuts on C: drive but for some reason it won't create shortcuts if I change the directory to any drive other than c:. For example, the following doesn't work:

    ------------------------
    CD "F:Coreldraw Files A-ZWKG"

    FOR %%a IN (*.cdr) DO SHORTCUT /t:"F:Coreldraw Files A-ZWKG%%a" /f:"%%a.lnk" /a:c
    ------------------------

    What am I doing wrong?

    Thanks,

    Chris

  12. #12
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Batchfile to make shortcuts - possible? (XP Pr

    CD won't change drives, just directories on the current drive. You need to precede your CD line with the following separate (and very short) command:<pre>F:</pre>


  13. #13
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Batchfile to make shortcuts - possible? (XP Pr

    Put a PAUSE after the CD, and you will see that it doesn't work because you are also attempting to change the current drive. Do CD /? to see the command syntax.

    You need
    CD /D "F:Coreldraw Files A-ZWKG"

    Also, you shouldn't need to specify the full path after the /t parameter because you're at that drive and directory already, although it does no harm...

    So I'd use:<pre>CD /D "F:Coreldraw Files A-ZWKG"
    PAUSE
    FOR %%a IN (*.cdr) DO SHORTCUT /t:"%%a" /f:"%%a.lnk" /a:c</pre>

    and I would replace the SHORTCUT by ECHO for the first run, just to see if it looks right.

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  14. #14
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Batchfile to make shortcuts - possible? (XP Pr

    I should probably add that an alternative way to skin the cat would be to forget changing the current directory and just specify the directory in your main command -- i.e., change <font face="Georgia">FOR %%a IN (*.cdr) DO ...</font face=georgia> to <font face="Georgia">FOR %%a IN ("F:Coreldraw Files A-ZWKG*.cdr") DO ...</font face=georgia>.

    UPDATE: The Bobbing Badger has returned! (Did I mention he's a Batch File Wizard?) I'm going to withdraw before I embarrass myself. (Who knew CD had a /D switch?)

  15. #15
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Batchfile to make shortcuts - possible? (XP Pr

    Thanks John, the /d switch works but I do need the path repeated as follows:

    CD /D "F:Coreldraw Files A-ZWKG"
    FOR %%a IN (*.cdr) DO SHORTCUT /t:"F:Coreldraw Files A-ZWKG%%a" /f:"%%a.lnk" /a:c

    If I don't repeat the path I get system error 87 and no shortcut is created.

    Best wishes,

    Chris

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •