Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Script to MOVE file and leave a Shortcut to new location

Reply
Thread Tools Display Modes

Script to MOVE file and leave a Shortcut to new location

 
 
JJ
Guest
Posts: n/a

 
      07-22-2009
Hi.

I am running low on disk space on my server, but need to keep all files
available. I would like to create a script that will move files that have
not been accessed after a preset date, to an external hard drive, leaving a
shortcut where the moved file originally was and pointing to it's new
location on the external drive.

So far, I have come up with robocopy to move the files by access date, but
it doesn't seem to have the ability to leave a shortcut behind.

Any ideas would be greatly appreciated!!!


Thanks,


James Thibault


 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      07-22-2009

"JJ" <> wrote in message
news:ee60$4a67328f$4801c552$...
> Hi.
>
> I am running low on disk space on my server, but need to keep all files
> available. I would like to create a script that will move files that have
> not been accessed after a preset date, to an external hard drive, leaving
> a shortcut where the moved file originally was and pointing to it's new
> location on the external drive.
>
> So far, I have come up with robocopy to move the files by access date, but
> it doesn't seem to have the ability to leave a shortcut behind.
>
> Any ideas would be greatly appreciated!!!
>
>
> Thanks,
>
>
> James Thibault


You could use shortcut.exe from http://www.optimumx.com/download/#Shortcut.


 
Reply With Quote
 
JJ
Guest
Posts: n/a

 
      07-22-2009
Thanks for the reply, Pegasus, but I will be moving thousands of files and
folders and subfolders. A huge directory tree. I don't see an option in the
switches to do all this in one step. Could you give me an example?

Say I wanted to move all files not accessed after Jan 1, 2003 from c:\ to
f:\Backup. I know how to do this with robocopy. How would I use shortcut.exe
to create shortcuts to all the files moved........in the locations hat they
were moved from....throughout the whole directory tree?

?

James

"Pegasus [MVP]" <> wrote in message
news:%...
>
> "JJ" <> wrote in message
> news:ee60$4a67328f$4801c552$...
>> Hi.
>>
>> I am running low on disk space on my server, but need to keep all files
>> available. I would like to create a script that will move files that
>> have not been accessed after a preset date, to an external hard drive,
>> leaving a shortcut where the moved file originally was and pointing to
>> it's new location on the external drive.
>>
>> So far, I have come up with robocopy to move the files by access date,
>> but it doesn't seem to have the ability to leave a shortcut behind.
>>
>> Any ideas would be greatly appreciated!!!
>>
>>
>> Thanks,
>>
>>
>> James Thibault

>
> You could use shortcut.exe from
> http://www.optimumx.com/download/#Shortcut.
>



 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a

 
      07-22-2009

All you need to do is to invoke shortcut.exe once for each file, giving it
the appropriate names each time, e.g. like so:
@echo off
for %%a in (E:\Backup\*.*) do (
echo shortcut /F:"C:\%%~na.lnk" /A:C /T:"%%a" /W:E:\Backup /R:1
)

Since your description about the source and target folders is rather vague,
you may have to tweak the above batch file a little in order to suit your
environment. Note also this:
- You must test the batch file from the Command Prompt. Do not test it from
the Start/Run box.
- When you're happy with the result you see, remove the word "echo" in Line
3 in order to activate the batch file.


"JJ" <> wrote in message
news:80d7d$4a67515d$4801c552$...
> Thanks for the reply, Pegasus, but I will be moving thousands of files and
> folders and subfolders. A huge directory tree. I don't see an option in
> the switches to do all this in one step. Could you give me an example?
>
> Say I wanted to move all files not accessed after Jan 1, 2003 from c:\ to
> f:\Backup. I know how to do this with robocopy. How would I use
> shortcut.exe to create shortcuts to all the files moved........in the
> locations hat they were moved from....throughout the whole directory tree?
>
> ?
>
> James
>
> "Pegasus [MVP]" <> wrote in message
> news:%...
>>
>> "JJ" <> wrote in message
>> news:ee60$4a67328f$4801c552$...
>>> Hi.
>>>
>>> I am running low on disk space on my server, but need to keep all files
>>> available. I would like to create a script that will move files that
>>> have not been accessed after a preset date, to an external hard drive,
>>> leaving a shortcut where the moved file originally was and pointing to
>>> it's new location on the external drive.
>>>
>>> So far, I have come up with robocopy to move the files by access date,
>>> but it doesn't seem to have the ability to leave a shortcut behind.
>>>
>>> Any ideas would be greatly appreciated!!!
>>>
>>>
>>> Thanks,
>>>
>>>
>>> James Thibault

>>
>> You could use shortcut.exe from
>> http://www.optimumx.com/download/#Shortcut.
>>

>
>



 
Reply With Quote
 
JJ
Guest
Posts: n/a

 
      07-22-2009
Thanks...I'll give it a try!


"Pegasus [MVP]" <> wrote in message
news:...
>
> All you need to do is to invoke shortcut.exe once for each file, giving it
> the appropriate names each time, e.g. like so:
> @echo off
> for %%a in (E:\Backup\*.*) do (
> echo shortcut /F:"C:\%%~na.lnk" /A:C /T:"%%a" /W:E:\Backup /R:1
> )
>
> Since your description about the source and target folders is rather
> vague, you may have to tweak the above batch file a little in order to
> suit your environment. Note also this:
> - You must test the batch file from the Command Prompt. Do not test it
> from the Start/Run box.
> - When you're happy with the result you see, remove the word "echo" in
> Line 3 in order to activate the batch file.
>
>
> "JJ" <> wrote in message
> news:80d7d$4a67515d$4801c552$...
>> Thanks for the reply, Pegasus, but I will be moving thousands of files
>> and folders and subfolders. A huge directory tree. I don't see an option
>> in the switches to do all this in one step. Could you give me an example?
>>
>> Say I wanted to move all files not accessed after Jan 1, 2003 from c:\ to
>> f:\Backup. I know how to do this with robocopy. How would I use
>> shortcut.exe to create shortcuts to all the files moved........in the
>> locations hat they were moved from....throughout the whole directory
>> tree?
>>
>> ?
>>
>> James
>>
>> "Pegasus [MVP]" <> wrote in message
>> news:%...
>>>
>>> "JJ" <> wrote in message
>>> news:ee60$4a67328f$4801c552$...
>>>> Hi.
>>>>
>>>> I am running low on disk space on my server, but need to keep all files
>>>> available. I would like to create a script that will move files that
>>>> have not been accessed after a preset date, to an external hard drive,
>>>> leaving a shortcut where the moved file originally was and pointing to
>>>> it's new location on the external drive.
>>>>
>>>> So far, I have come up with robocopy to move the files by access date,
>>>> but it doesn't seem to have the ability to leave a shortcut behind.
>>>>
>>>> Any ideas would be greatly appreciated!!!
>>>>
>>>>
>>>> Thanks,
>>>>
>>>>
>>>> James Thibault
>>>
>>> You could use shortcut.exe from
>>> http://www.optimumx.com/download/#Shortcut.
>>>

>>
>>

>
>



 
Reply With Quote
 
Al Dunbar
Guest
Posts: n/a

 
      07-26-2009
Copy the code below into a batch file (i.e. backfill.cmd) - watch for line
wrapping - and then run it from a command prompt window with two parameters:

backfill "E:\backup" "C:\"

This script expands on Pegasus' contribution by processing all of the files
contained within the "huge directory tree" that is C:\backup using the "/R"
switch of the FOR command. It also avoids re-creating any already existing
shortcuts, so you could run it after your subsequent robocopy cleanup runs.

When you are satisfied that the commands being displayed will do the trick,
change "ECHO/shortcut.exe" to "shortcut.exe".

REM -----------------------
@echo off
setlocal

(set _sce=%~dpnx1)
(set _dst=%~dpnx2)
if not defined _dst (
echo/syntax: %~nx0 [folder for files] [folder for shortcuts]
pause
GOTO:EOF
)

for /r b %%A in (*.*) do CALL:SCUT "%%~A"
GOTO:EOF

:SCUT

(set _FILE=%~1)
(call set _SCUT=%%_FILE:%_sce%=%_dst%%%)
for %%B in ("%_SCUT%") do (set _SCUT=%%~dpnB.lnk)
echo/
if exist "%_SCUT%" (
echo/shortcut already exists: "%_SCUT%" & pause
) else (
ECHO/shortcut.exe /F:"%_SCUT%" /A:C /T:"%_FILE%"
)

GOTO:EOF
REM -----------------------


/Al

"JJ" <> wrote in message
news:d6891$4a677784$4801c552$...
> Thanks...I'll give it a try!
>
>
> "Pegasus [MVP]" <> wrote in message
> news:...
>>
>> All you need to do is to invoke shortcut.exe once for each file, giving
>> it the appropriate names each time, e.g. like so:
>> @echo off
>> for %%a in (E:\Backup\*.*) do (
>> echo shortcut /F:"C:\%%~na.lnk" /A:C /T:"%%a" /W:E:\Backup /R:1
>> )
>>
>> Since your description about the source and target folders is rather
>> vague, you may have to tweak the above batch file a little in order to
>> suit your environment. Note also this:
>> - You must test the batch file from the Command Prompt. Do not test it
>> from the Start/Run box.
>> - When you're happy with the result you see, remove the word "echo" in
>> Line 3 in order to activate the batch file.
>>
>>
>> "JJ" <> wrote in message
>> news:80d7d$4a67515d$4801c552$...
>>> Thanks for the reply, Pegasus, but I will be moving thousands of files
>>> and folders and subfolders. A huge directory tree. I don't see an option
>>> in the switches to do all this in one step. Could you give me an
>>> example?
>>>
>>> Say I wanted to move all files not accessed after Jan 1, 2003 from c:\
>>> to f:\Backup. I know how to do this with robocopy. How would I use
>>> shortcut.exe to create shortcuts to all the files moved........in the
>>> locations hat they were moved from....throughout the whole directory
>>> tree?
>>>
>>> ?
>>>
>>> James
>>>
>>> "Pegasus [MVP]" <> wrote in message
>>> news:%...
>>>>
>>>> "JJ" <> wrote in message
>>>> news:ee60$4a67328f$4801c552$...
>>>>> Hi.
>>>>>
>>>>> I am running low on disk space on my server, but need to keep all
>>>>> files available. I would like to create a script that will move files
>>>>> that have not been accessed after a preset date, to an external hard
>>>>> drive, leaving a shortcut where the moved file originally was and
>>>>> pointing to it's new location on the external drive.
>>>>>
>>>>> So far, I have come up with robocopy to move the files by access date,
>>>>> but it doesn't seem to have the ability to leave a shortcut behind.
>>>>>
>>>>> Any ideas would be greatly appreciated!!!
>>>>>
>>>>>
>>>>> Thanks,
>>>>>
>>>>>
>>>>> James Thibault
>>>>
>>>> You could use shortcut.exe from
>>>> http://www.optimumx.com/download/#Shortcut.
>>>>
>>>
>>>

>>
>>

>
>




 
Reply With Quote
 
Al Dunbar
Guest
Posts: n/a

 
      07-26-2009
Oops, I forgot to remove a PAUSE statement...
th
A few more thoughts...

- If users have read/write access there is a possibility that shortcut.exe
will fail because the folder to where the shortcut is to go has been deleted
or renamed since the file was moved.

- If you do subsequent cleanup robocopy runs, perhaps these should go to
different folders, E:\backup2, E:\backup3, etc.

- Except for the fact that the shortcuts could be moved or renamed, you
could run a script to look through E:\backup and delete files whose
shortcuts have been deleted.

- I just realized there could be name collisions. Suppose you have files
test.doc and test.rtf in the same folder. It appears to me that the code
below will try to make two shortcuts called test.lnk. To have it create
test.rtf.lnk and test.doc.lnk instead, change this line:

(set _SCUT=%%~dpnB.lnk)

to this:

(set _SCUT=%%~dpnxB.lnk)


/Al

"Al Dunbar" <> wrote in message
news:...
> Copy the code below into a batch file (i.e. backfill.cmd) - watch for line
> wrapping - and then run it from a command prompt window with two
> parameters:
>
> backfill "E:\backup" "C:\"
>
> This script expands on Pegasus' contribution by processing all of the
> files contained within the "huge directory tree" that is C:\backup using
> the "/R" switch of the FOR command. It also avoids re-creating any already
> existing shortcuts, so you could run it after your subsequent robocopy
> cleanup runs.
>
> When you are satisfied that the commands being displayed will do the
> trick, change "ECHO/shortcut.exe" to "shortcut.exe".
>
> REM -----------------------
> @echo off
> setlocal
>
> (set _sce=%~dpnx1)
> (set _dst=%~dpnx2)
> if not defined _dst (
> echo/syntax: %~nx0 [folder for files] [folder for shortcuts]
> pause
> GOTO:EOF
> )
>
> for /r b %%A in (*.*) do CALL:SCUT "%%~A"
> GOTO:EOF
>
> :SCUT
>
> (set _FILE=%~1)
> (call set _SCUT=%%_FILE:%_sce%=%_dst%%%)
> for %%B in ("%_SCUT%") do (set _SCUT=%%~dpnB.lnk)
> echo/
> if exist "%_SCUT%" (
> echo/shortcut already exists: "%_SCUT%" & pause
> ) else (
> ECHO/shortcut.exe /F:"%_SCUT%" /A:C /T:"%_FILE%"
> )
>
> GOTO:EOF
> REM -----------------------
>
>
> /Al
>
> "JJ" <> wrote in message
> news:d6891$4a677784$4801c552$...
>> Thanks...I'll give it a try!
>>
>>
>> "Pegasus [MVP]" <> wrote in message
>> news:...
>>>
>>> All you need to do is to invoke shortcut.exe once for each file, giving
>>> it the appropriate names each time, e.g. like so:
>>> @echo off
>>> for %%a in (E:\Backup\*.*) do (
>>> echo shortcut /F:"C:\%%~na.lnk" /A:C /T:"%%a" /W:E:\Backup /R:1
>>> )
>>>
>>> Since your description about the source and target folders is rather
>>> vague, you may have to tweak the above batch file a little in order to
>>> suit your environment. Note also this:
>>> - You must test the batch file from the Command Prompt. Do not test it
>>> from the Start/Run box.
>>> - When you're happy with the result you see, remove the word "echo" in
>>> Line 3 in order to activate the batch file.
>>>
>>>
>>> "JJ" <> wrote in message
>>> news:80d7d$4a67515d$4801c552$...
>>>> Thanks for the reply, Pegasus, but I will be moving thousands of files
>>>> and folders and subfolders. A huge directory tree. I don't see an
>>>> option in the switches to do all this in one step. Could you give me an
>>>> example?
>>>>
>>>> Say I wanted to move all files not accessed after Jan 1, 2003 from c:\
>>>> to f:\Backup. I know how to do this with robocopy. How would I use
>>>> shortcut.exe to create shortcuts to all the files moved........in the
>>>> locations hat they were moved from....throughout the whole directory
>>>> tree?
>>>>
>>>> ?
>>>>
>>>> James
>>>>
>>>> "Pegasus [MVP]" <> wrote in message
>>>> news:%...
>>>>>
>>>>> "JJ" <> wrote in message
>>>>> news:ee60$4a67328f$4801c552$...
>>>>>> Hi.
>>>>>>
>>>>>> I am running low on disk space on my server, but need to keep all
>>>>>> files available. I would like to create a script that will move
>>>>>> files that have not been accessed after a preset date, to an external
>>>>>> hard drive, leaving a shortcut where the moved file originally was
>>>>>> and pointing to it's new location on the external drive.
>>>>>>
>>>>>> So far, I have come up with robocopy to move the files by access
>>>>>> date, but it doesn't seem to have the ability to leave a shortcut
>>>>>> behind.
>>>>>>
>>>>>> Any ideas would be greatly appreciated!!!
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>>
>>>>>> James Thibault
>>>>>
>>>>> You could use shortcut.exe from
>>>>> http://www.optimumx.com/download/#Shortcut.
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>
>




 
Reply With Quote
 
JJ
Guest
Posts: n/a

 
      08-13-2009
Thanks so much, Al! I will let you know how it goes.


James



"Al Dunbar" <> wrote in message
news:%...
> Oops, I forgot to remove a PAUSE statement...
> th
> A few more thoughts...
>
> - If users have read/write access there is a possibility that shortcut.exe
> will fail because the folder to where the shortcut is to go has been
> deleted or renamed since the file was moved.
>
> - If you do subsequent cleanup robocopy runs, perhaps these should go to
> different folders, E:\backup2, E:\backup3, etc.
>
> - Except for the fact that the shortcuts could be moved or renamed, you
> could run a script to look through E:\backup and delete files whose
> shortcuts have been deleted.
>
> - I just realized there could be name collisions. Suppose you have files
> test.doc and test.rtf in the same folder. It appears to me that the code
> below will try to make two shortcuts called test.lnk. To have it create
> test.rtf.lnk and test.doc.lnk instead, change this line:
>
> (set _SCUT=%%~dpnB.lnk)
>
> to this:
>
> (set _SCUT=%%~dpnxB.lnk)
>
>
> /Al
>
> "Al Dunbar" <> wrote in message
> news:...
>> Copy the code below into a batch file (i.e. backfill.cmd) - watch for
>> line wrapping - and then run it from a command prompt window with two
>> parameters:
>>
>> backfill "E:\backup" "C:\"
>>
>> This script expands on Pegasus' contribution by processing all of the
>> files contained within the "huge directory tree" that is C:\backup using
>> the "/R" switch of the FOR command. It also avoids re-creating any
>> already existing shortcuts, so you could run it after your subsequent
>> robocopy cleanup runs.
>>
>> When you are satisfied that the commands being displayed will do the
>> trick, change "ECHO/shortcut.exe" to "shortcut.exe".
>>
>> REM -----------------------
>> @echo off
>> setlocal
>>
>> (set _sce=%~dpnx1)
>> (set _dst=%~dpnx2)
>> if not defined _dst (
>> echo/syntax: %~nx0 [folder for files] [folder for shortcuts]
>> pause
>> GOTO:EOF
>> )
>>
>> for /r b %%A in (*.*) do CALL:SCUT "%%~A"
>> GOTO:EOF
>>
>> :SCUT
>>
>> (set _FILE=%~1)
>> (call set _SCUT=%%_FILE:%_sce%=%_dst%%%)
>> for %%B in ("%_SCUT%") do (set _SCUT=%%~dpnB.lnk)
>> echo/
>> if exist "%_SCUT%" (
>> echo/shortcut already exists: "%_SCUT%" & pause
>> ) else (
>> ECHO/shortcut.exe /F:"%_SCUT%" /A:C /T:"%_FILE%"
>> )
>>
>> GOTO:EOF
>> REM -----------------------
>>
>>
>> /Al
>>
>> "JJ" <> wrote in message
>> news:d6891$4a677784$4801c552$...
>>> Thanks...I'll give it a try!
>>>
>>>
>>> "Pegasus [MVP]" <> wrote in message
>>> news:...
>>>>
>>>> All you need to do is to invoke shortcut.exe once for each file, giving
>>>> it the appropriate names each time, e.g. like so:
>>>> @echo off
>>>> for %%a in (E:\Backup\*.*) do (
>>>> echo shortcut /F:"C:\%%~na.lnk" /A:C /T:"%%a" /W:E:\Backup /R:1
>>>> )
>>>>
>>>> Since your description about the source and target folders is rather
>>>> vague, you may have to tweak the above batch file a little in order to
>>>> suit your environment. Note also this:
>>>> - You must test the batch file from the Command Prompt. Do not test it
>>>> from the Start/Run box.
>>>> - When you're happy with the result you see, remove the word "echo" in
>>>> Line 3 in order to activate the batch file.
>>>>
>>>>
>>>> "JJ" <> wrote in message
>>>> news:80d7d$4a67515d$4801c552$...
>>>>> Thanks for the reply, Pegasus, but I will be moving thousands of files
>>>>> and folders and subfolders. A huge directory tree. I don't see an
>>>>> option in the switches to do all this in one step. Could you give me
>>>>> an example?
>>>>>
>>>>> Say I wanted to move all files not accessed after Jan 1, 2003 from c:\
>>>>> to f:\Backup. I know how to do this with robocopy. How would I use
>>>>> shortcut.exe to create shortcuts to all the files moved........in the
>>>>> locations hat they were moved from....throughout the whole directory
>>>>> tree?
>>>>>
>>>>> ?
>>>>>
>>>>> James
>>>>>
>>>>> "Pegasus [MVP]" <> wrote in message
>>>>> news:%...
>>>>>>
>>>>>> "JJ" <> wrote in message
>>>>>> news:ee60$4a67328f$4801c552$...
>>>>>>> Hi.
>>>>>>>
>>>>>>> I am running low on disk space on my server, but need to keep all
>>>>>>> files available. I would like to create a script that will move
>>>>>>> files that have not been accessed after a preset date, to an
>>>>>>> external hard drive, leaving a shortcut where the moved file
>>>>>>> originally was and pointing to it's new location on the external
>>>>>>> drive.
>>>>>>>
>>>>>>> So far, I have come up with robocopy to move the files by access
>>>>>>> date, but it doesn't seem to have the ability to leave a shortcut
>>>>>>> behind.
>>>>>>>
>>>>>>> Any ideas would be greatly appreciated!!!
>>>>>>>
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>>
>>>>>>> James Thibault
>>>>>>
>>>>>> You could use shortcut.exe from
>>>>>> http://www.optimumx.com/download/#Shortcut.
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>
>>

>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Must I move the AD Groups I've created to the Default location so my script can see them, or is there another way...? Kelvin Active Directory 1 08-20-2009 05:24 PM
RE: Should I move my exchange store from it's default location or leave it where it is? Terence Liu [MSFT] Windows Small Business Server 0 11-26-2007 08:21 AM
Re: Should I move my exchange store from it's default location or leave it where it is? Lanwench [MVP - Exchange] Windows Small Business Server 0 11-20-2007 07:28 PM
Move EPG file location dcdc Windows Media Center 4 07-06-2006 06:42 PM
script to copy a shortcut from a location on our server to the all users desktop and all users start menu Woody Scripting 1 11-19-2005 02:24 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59