DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: DONE: Move files, replace with shortcuts to those files  (Read 12,277 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
DONE: Move files, replace with shortcuts to those files
« on: March 12, 2015, 04:07 AM »
Move a number of files (let's suppose pdfs) from Folder A, to Folder B.

Create in Folder A corresponding shortcuts to each moved file, now in Folder B.

Any suggestions?

Assume that Folder B already has lots of files, and the ones you are moving over will get mixed with the rest there -- not a simple matter of moving to an empty folder.

Thanks!

Nicholas Kormanik

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: DONE: Move files, replace with shortcuts to those files
« Reply #1 on: March 12, 2015, 05:41 AM »
And how do you handle file collision?
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: DONE: Move files, replace with shortcuts to those files
« Reply #2 on: March 12, 2015, 06:52 AM »
Rename.  Add suffix, say, 001, etc.

Thanks much for asking.

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: DONE: Move files, replace with shortcuts to those files
« Reply #3 on: March 12, 2015, 12:22 PM »
Requires Shortcut.exe from here, put it in C:\Scripts or edit the command file to point to where you've copied it.

MovenShortcut.cmd

Installation:
Copy it somewhere.

Running:
Double-click it.

Code: (generic)
@if (@CodeSection == @Batch) @then

    @echo off
    color 1a
    setlocal EnableExtensions
    setlocal DisableDelayedExpansion
    
    echo Select SOURCE folder
    for /F "delims=" %%S in ('CScript //nologo //E:JScript "%~F0"') do (
        set srce=%%S
    )
    if "%srce%"=="" goto :End2
    echo Selected folder: "%srce%"
    
    echo Select DESTINATION folder
    for /F "delims=" %%D in ('CScript //nologo //E:JScript "%~F0"') do (
       set dest=%%D
    )
    if "%dest%"=="" goto :End2
    
    echo Selected folder: "%dest%"
    
    if "%srce%"=="%dest%" goto :End1
    
    :GetExt
    echo.
    set /P ext=Please enter extension [eg. jpg] ENTER to exit: 
    if %ext%=="" goto :End2
    
    for /r "%srce%" %%a in (*.%ext%) do (call :ProcessFile "%%~fa")

    :End
    set ext=
    goto :GetExt
    
    :End1
    color 1c
    echo **** SOURCE and DESTINATION are the same! ****
    :End2
    set srce=
    set dest=
    pause
    exit

    :ProcessFile
    setlocal
    if not exist "%dest%\%~nx1" goto :move2
    :loop
    set /a fileCounter+=1
    set "fileName=%~n1__%filecounter%%~x1"
    if exist "%dest%\%fileName%" goto :loop
    move "%~1" "%dest%\%filename%"
rem Full path to Shortcut.exe
    C:\Scripts\shortcut.exe /F:"%~dpn1.lnk" /A:C /T:"%dest%\%filename%"
    goto :endProcessFile
    
    :move2
    move "%~1" "%dest%"
rem Full path to Shortcut.exe
    C:\Scripts\shortcut.exe /F:"%~dpn1.lnk" /A:C /T:"%dest%\%~nx1"

    :endProcessFile
    endlocal
    goto :eof

    endlocal
    End of Batch section
@end


// JScript section

// Creates a dialog box that enables the user to select a folder and display it.
var title = "Select a folder", rootFolder = 0x11;
var shl = new ActiveXObject("Shell.Application");
var folder = shl.BrowseForFolder(0, title, 0, rootFolder);
WScript.Stdout.WriteLine(folder ? folder.self.path : "");

File collisions will be renamed: {filename}__{number}.{ext}

So goes the theory.
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 563
Re: DONE: Move files, replace with shortcuts to those files
« Reply #4 on: March 13, 2015, 02:05 AM »
Beautifully done.  Works like a charm.  Even between different drives.

Thanks very much, 4wd.  Great job.

Nicholas

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: Move files, replace with shortcuts to those files
« Reply #5 on: March 21, 2015, 06:44 PM »
Nice work, 4wd.  I'll move this.  :Thmbsup:

Original address: https://www.donationcoder.com/forum/index.php?topic=40412.0