topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday December 13, 2024, 10:49 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

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

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
DONE: Move files, replace with shortcuts to those files
« on: March 11, 2015, 11:07 PM »
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: DONE: Move files, replace with shortcuts to those files
« Reply #1 on: March 12, 2015, 12:41 AM »
And how do you handle file collision?

nkormanik

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

Thanks much for asking.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: DONE: Move files, replace with shortcuts to those files
« Reply #3 on: March 12, 2015, 07:22 AM »
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: Text [Select]
  1. @if (@CodeSection == @Batch) @then
  2.  
  3.     @echo off
  4.     color 1a
  5.     setlocal EnableExtensions
  6.     setlocal DisableDelayedExpansion
  7.    
  8.     echo Select SOURCE folder
  9.     for /F "delims=" %%S in ('CScript //nologo //E:JScript "%~F0"') do (
  10.         set srce=%%S
  11.     )
  12.     if "%srce%"=="" goto :End2
  13.     echo Selected folder: "%srce%"
  14.    
  15.     echo Select DESTINATION folder
  16.     for /F "delims=" %%D in ('CScript //nologo //E:JScript "%~F0"') do (
  17.        set dest=%%D
  18.     )
  19.     if "%dest%"=="" goto :End2
  20.    
  21.     echo Selected folder: "%dest%"
  22.    
  23.     if "%srce%"=="%dest%" goto :End1
  24.    
  25.     :GetExt
  26.     echo.
  27.     set /P ext=Please enter extension [eg. jpg] ENTER to exit:
  28.     if %ext%=="" goto :End2
  29.    
  30.     for /r "%srce%" %%a in (*.%ext%) do (call :ProcessFile "%%~fa")
  31.  
  32.     :End
  33.     set ext=
  34.     goto :GetExt
  35.    
  36.     :End1
  37.     color 1c
  38.     echo **** SOURCE and DESTINATION are the same! ****
  39.     :End2
  40.     set srce=
  41.     set dest=
  42.     pause
  43.     exit
  44.  
  45.     :ProcessFile
  46.     setlocal
  47.     if not exist "%dest%\%~nx1" goto :move2
  48.     :loop
  49.     set /a fileCounter+=1
  50.     set "fileName=%~n1__%filecounter%%~x1"
  51.     if exist "%dest%\%fileName%" goto :loop
  52.     move "%~1" "%dest%\%filename%"
  53. rem Full path to Shortcut.exe
  54.     C:\Scripts\shortcut.exe /F:"%~dpn1.lnk" /A:C /T:"%dest%\%filename%"
  55.     goto :endProcessFile
  56.    
  57.     :move2
  58.     move "%~1" "%dest%"
  59. rem Full path to Shortcut.exe
  60.     C:\Scripts\shortcut.exe /F:"%~dpn1.lnk" /A:C /T:"%dest%\%~nx1"
  61.  
  62.     :endProcessFile
  63.     endlocal
  64.     goto :eof
  65.  
  66.     endlocal
  67.     End of Batch section
  68. @end
  69.  
  70.  
  71. // JScript section
  72.  
  73. // Creates a dialog box that enables the user to select a folder and display it.
  74. var title = "Select a folder", rootFolder = 0x11;
  75. var shl = new ActiveXObject("Shell.Application");
  76. var folder = shl.BrowseForFolder(0, title, 0, rootFolder);
  77. WScript.Stdout.WriteLine(folder ? folder.self.path : "");

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

So goes the theory.

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 554
    • View Profile
    • Donate to Member
Re: DONE: Move files, replace with shortcuts to those files
« Reply #4 on: March 12, 2015, 09:05 PM »
Beautifully done.  Works like a charm.  Even between different drives.

Thanks very much, 4wd.  Great job.

Nicholas


skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: DONE: Move files, replace with shortcuts to those files
« Reply #5 on: March 21, 2015, 01:44 PM »
Nice work, 4wd.  I'll move this.   :Thmbsup: