Symbolically link new files?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ihaterich
Posts: 4
Joined: 08 Aug 2010 12:43

Symbolically link new files?

#1 Post by ihaterich » 08 Aug 2010 12:46

I want to write a batch file that will search my hard drive for new media files, and create symbolic links for these files in a new directory. How can I do this?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Symbolically link new files?

#2 Post by aGerman » 08 Aug 2010 14:15

ihaterich wrote:I want to write a batch file that will search my hard drive for new media files,

What means "new" in your case?

ihaterich wrote:and create symbolic links for these files in a new directory. How can I do this?

You can't create links using batch, sorry.

Regards
aGerman

ihaterich
Posts: 4
Joined: 08 Aug 2010 12:43

Re: Symbolically link new files?

#3 Post by ihaterich » 08 Aug 2010 14:39

Thanks for the reply. I've read mklink could be used to create symbolic links. Is this not correct?

I would define new as being files added in the last 12 hours. Thanks

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Symbolically link new files?

#4 Post by aGerman » 08 Aug 2010 16:38

Hmm, I could try to make a chimera of batch and VBScript.
What file extensions would you look for?
In which directory should all the links be placed?

You should think about that searching over the entire hard drive will take a lot of time. Maybe you can restrict it some more.

Regards
aGerman

ihaterich
Posts: 4
Joined: 08 Aug 2010 12:43

Re: Symbolically link new files?

#5 Post by ihaterich » 08 Aug 2010 16:44

Hi, I would only be looking for extensions .avi .mpg .mp4 .mov .wmv. and .mov

The link folder would be D:\Other\New

I would only need it to search G:\Downloads

thanks again

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Symbolically link new files?

#6 Post by aGerman » 08 Aug 2010 16:57

OK. It's almost 1:00 am in Germany, so I have to sleep some hours. I don't forget to write a code for you, but sorry -- not now :wink:

Regards
aGerman

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Symbolically link new files?

#7 Post by aGerman » 09 Aug 2010 03:11

Here it comes:

Code: Select all

@echo off &setlocal
:: source folder, without final back slash
set "sourceRoot=G:\Downloads"

:: destination folder, without final back slash
set "destFolder=D:\Other\New"

:: search extensions, space separated
set "extensions=*.avi *.mpg *.mp4 *.mov *.wmv"

(
echo\sFileName = WScript.Arguments^(0^) : sFolderName = WScript.Arguments^(1^)
echo\Set oFile = WScript.CreateObject^("Scripting.FileSystemObject"^).GetFile^(sFileName^)
echo\If DateAdd^("h", -12, Now^) ^<= oFile.DateCreated Then
echo\  set oSc = WScript.CreateObject^("WScript.Shell"^).CreateShortcut^("%destFolder%\" ^& oFile.Name ^& ".lnk"^)
echo\  oSc.Description = sFileName
echo\  oSc.TargetPath = sFileName
echo\  oSc.WindowStyle = 1
echo\  oSc.WorkingDirectory = sFolderName
echo\  oSc.Save
echo\End If
)>"%temp%\tmp.vbs"

md "%destFolder%" 2>nul
pushd "%sourceRoot%" ||goto :eof
for /r %%a in (%extensions%) do call "%temp%\tmp.vbs" "%%~a" "%%~dpa"
popd
del "%temp%\tmp.vbs"
pause


If something isn't clear, come back with your issues.

Regards
aGerman

ihaterich
Posts: 4
Joined: 08 Aug 2010 12:43

Re: Symbolically link new files?

#8 Post by ihaterich » 09 Aug 2010 11:07

Thanks so much for your help

Post Reply