Creating a shortcut of a folder above the executive file, in anotherpart of the filetree - batch-file

I'm trying to bring some structure en efficiency to the current NAS at my work. I want to use shortcuts to minimise the data transfers.
My file structure would be something like this:
NAS/Shortcuts/
NAS/Allfiles/Projects/555(projectnumber)
I want to store all files in one folder.
In this folder, I would like to make a clickable file that runs a script of some sort to automatically make a shortcut of the folder 555. or the next project file that is cppied in this map. Preferably it would be in a standard file structure so we could copy it with the standard project file layout structure and just click a runnable script to make a shortcut in NAS/Shortcuts with the correct name.
I know a bit of batch but I don't know how to automate the filename and fileposition.
I repeated myself some times I'm not sure if I'm being clear enough.
What I got right now
#echo off
set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "?" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "NAS/Shortcuts" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%`
cscript /nologo %SCRIPT%
del %SCRIPT%
but maybe this all need to be different?
Getting a solution to make a batch file that makes a shortcut of the filename where it is in in a different location.

Related

How to execute a Batchfile in a folder, by dropping the folder on the file

I have a small batch file that executes a few simple lines of code.
It works perfectly fine when I put it in the Folder and execute it.
However the file should be located on level above it and be able to get executed by having the folder being droped on to it.
When I currently drop the folder on to it, it just executes the code as if I would just double click it. However it should behave as if the file was located inside the folder.
#echo off
for %%a in (*.*) do #echo %%~na >> filenames.txt
)
pause
How would I do that?
I don't want to apply it to every folder just the one chosen by dropping it onto the file.
I want to generate a file from all the filenames inside the Folder.
which will then be compared to an other file created from an other folder.
#echo off
echo new additions > test3.txt
findstr /vixg:shots.txt shots2.txt >> test3.txt
echo removed >> test3.txt
findstr /vixg:shots2.txt shots.txt >> test3.txt
I assume I can|t automate the comparison, by dropping two folders onto the file, can I?
I am not 100% sure what you want, but I am assuming you want to match shots.txt which is in folder1 with shots2.txt in folder2. Something like this should work if that is the case:
#echo off
echo new additions > test3.txt
if exist "%1\shots.txt" (findstr /vixg:"%1\shots.txt" "%2\shots2.txt" >> test3.txt)
if exist "%2\shots.txt" (findstr /vixg:"%2\shots.txt" "%1\shots2.txt" >> test3.txt)
echo removed >> test3.txt
if exist "%1\shots2.txt" (findstr /vixg:"%1\shots2.txt" "%2\shots.txt" >> test3.txt)
if exist "%2\shots.txt" (findstr /vixg:"%2\shots2.txt" "%1\shots.txt" >> test3.txt)
You can then select 2 folders containing the files and drop them both onto the batch file.

Playing folder full of files from Disc in Windows Media Player in Batch

I'm making a batch file to play AVI files in a folder in Windows Media Player (WMP11). They must be able to play in this player so I can not use VLC.
Unfortunately it doesn't seem as simple as:
start wmplayer folder\*.avi
The media player website shows that it can play a single file, how can I get it to play all of a type, or make a temporary playlist so they can be played?
Borrowed from this : SuperUser.com
Answer. I'll put it here for
convenience & "archive" purposes, also adjusted for your Question.
Make sure .avi format is set to always "Open With" Windows Media Player.
1) Open a basic text editor (ie: Notepad) and paste the code shown further below.
2). Save it as PlayVids.cmd (or whatever you like but it must be saved as .cmd)
3) Double click the .cmd file to auto-open all files in folder at once. This gives you an auto-playlist.
Code for pasting into cmd file : (replace C:\MyVideos with your own Disc's drive + folder. If path is wrong it will fail/close)
#ECHO OFF
SET VIDFolder=C:\MyVideos
SET TempVBSFile=%tmp%\~tmpVIDTemp.vbs
:VBSDynamicBuild
IF EXIST "%TempVBSFile%" DEL /F /Q "%TempVBSFile%"
ECHO Set WshShell = WScript.CreateObject("WScript.Shell") >>"%TempVBSFile%"
ECHO WshShell.Run "%VIDFolder%" >>"%TempVBSFile%"
ECHO Wscript.Sleep 500 >>"%TempVBSFile%"
ECHO WshShell.SendKeys "^a" >>"%TempVBSFile%"
ECHO Wscript.Sleep 500 >>"%TempVBSFile%"
ECHO WshShell.SendKeys "{ENTER}" >>"%TempVBSFile%"
CSCRIPT //nologo "%TempVBSFile%"
GOTO EOF

How to make a .bat file and merge logs

Thank you for your helps in this web.
I must make a .bat file,to merge many logfiles in the same folder with log's filename.
I made the cmd program.
for %1 in (*.log) do echo [%1] >> all.txt & type %1 >> all.txt
I can go to the goal in the cmd,but .bat cannnot.
please help me!
** folder tree is
a folder a1.log
a2.log
a3.log...
b foledr b1.log
b2.log
b3.log...
so,i want merge
a1,a2,a3.log⇒a_all.txt
b1,b2,b3.log⇒b_all.txt
it is not problem that merged file name is same all.txt.
because i want check the two files with the winmerge.
Try this - the for variable percent signs need to be doubled in a batch file.
#echo off
for %%a in (*.log) do echo [%%a] >> all.txt & type "%%a" >> all.txt
pause

Works properly, but not when running as administrator

My batch file makes another batch file. It works when you run it normally.
#echo off
type NUL > batchfile.bat
ECHO #echo off >> batchfile.bat
ECHO set hostspath=%%windir%%\System32\drivers\etc\hosts >> batchfile.bat
ECHO exit >> batchfile.bat
exit
However, when you run it as an administrator, it doesnt work. I need to make it run properly also when running as administrator. What is the correct way to do it ?
When you run as administrator, it changes the current context directory. I'm not sure where it changes to, but you can avoid that problem by specifying the full output path to the new batch file, like so:
#echo off
type NUL > "C:\Users\Troy\Documents\Software\batch files\batchfile.bat"
ECHO #echo off >> "C:\Users\Troy\Documents\Software\batch files\batchfile.bat"
ECHO set hostspath=%%windir%%\System32\drivers\etc\hosts >> "C:\Users\Troy\Documents\Software\batch files\batchfile.bat"
ECHO exit >> "C:\Users\Troy\Documents\Software\batch files\batchfile.bat"
exit
UPDATE: I just discovered that there's a way to dynamically change the current directory to the same one as the currently executing batch file. So, the following is probably a cleaner solution. It just involves adding one line at the top of the original script:
cd %~dp0
#echo off
type NUL > batchfile.bat
ECHO #echo off >> batchfile.bat
ECHO set hostspath=%%windir%%\System32\drivers\etc\hosts >> batchfile.bat
ECHO exit >> batchfile.bat
exit

FTP commands in a batch script does not working properly

I've made a simple FTP upload script that should upload multiple files from a Windows 2008 Server to the FTP location. I've tried this manually by executing every command of the script directly in CMD and it works fine. However when I run script.bat it says that none of the commands are recognized as internal or external commands. I checked the ENV variables and there is a path to System32 so it should be fine. Can anyone please help with this. Thank you
open xx.xxx.xx.xx
user
pass
prompt
bin
lcd X:\test\test\
cd /tempTest/tempTest
binary
mput "*.*"
disconnect
quit
You can also try something like that with a batch file for multiple file Upload :
MultipleFileUpload.bat
#echo off
Title Multiple file Upload by Hackoo
mode con cols=85 lines=22 & Color A
::***********************************
Set FTPSERVER=ftp.xx.xxx.xx.xx.com
Set USER=UserName
Set Password=YourPassword
Set LocalFolder=X:\test\test
Set RemoteFolder=/tempTest/tempTest/
::***********************************
> ft.do echo Open %FTPSERVER%
>> ft.do echo %USER%
>> ft.do echo %Password%
>> ft.do echo prompt n
>> ft.do echo bin
>> ft.do echo lcd %LocalFolder%
>> ft.do echo cd %RemoteFolder%
>> ft.do echo mput *.*
>> ft.do echo bye
ftp -s:ft.do
del ft.do
Pause
Place your script in a text file on your desktop called ftpscript.txt
Create a batch file called getftp.bat and inside it have this - then you can click the bat file.
#echo off
ftp -i -s:"%userprofile%\desktop\ftpscript.txt"
pause

Resources