Run Skype through batch file (WindowsApp) - windows

I made a batch file to open Itunes because I found no other way to have permanent shrtcut with WindowsApp and it work. Here it is:
for /f "delims=" %%a in ('dir /b /ad /on "C:\Program Files\WindowsApps\AppleInc.iTunes_*"') do set ver=%%a
set "exec=C:\Program Files\WindowsApps\%ver%"
cd "%exec%"
iTunes.exe
However when I made it manually through Powershell, it opens another windows than the batch file. This isn't an issue but I want to know why.
At the opposite, with Skype, when I go in the Skype folder and I run Skype.exe manually it works but with the batch files, it does nothing. Here is the code:
for /f "delims=" %%a in ('dir /b /ad /on "C:\Program Files\WindowsApps\Microsoft.SkypeApp_*"') do set ver=%%a
set "exec=C:\Program Files\WindowsApps\%ver%\Skype"
cd "%exec%"
Skype.exe
I want the batch file to works as if I click on the Skype.exe file or run it manually
Thanks

Related

A batch file to move the most recent folders first?

A batch file to move the most recent folders first?
For example i have a batch file which moves folders from my local machine to a remote machine, is there a way to move the most recent created folders first?
Currently i have the following:
xcopy /s C:\Users\xxxx\Desktop\AutoFrameworkResults \\192.1xx.1.xx\xxxx\xxxxx\Common\AutoFrameworkResults
thanks for your help
I might be too late to the party but here is the script anyway.
setlocal
set "sourceDir=c:\users\xxxx\desktop\autoframeworkresults"
set "destDir=\\192.1xx.1xx\xxxx\xxxx\common\autoframeworkresults"
for /f "delims=" %%d in ('dir "%sourceDir%" /o-d /ad /b') do (
xcopy /s "%sourceDir%\%%d" "%destDir%\%%d\"
)

What's wrong with my batch script that moves the newest file from one folder to another?

I'm trying to put together a Windows batch script that moves the most recent file to a different directory. Here's my batch script mostly stolen from here:
FOR /F "tokens=*" %%G IN ('dir /b *.*') DO move %%G C:\Users\jrobinson\Desktop\ & exit /b
When I run this it moves every file in the folder. Interestingly, when I replace the MOVE command with a COPY command, the script copies only one file:
FOR /F "tokens=*" %%G IN ('dir /b *.*') DO copy %%G C:\Users\jrobinson\Desktop\ & exit /b
REM ---------------------------------------^^^^
Why is the move script moving every file while the copy script is only copying one file? Is it possibly because my script file is also in that folder and because of my edits, it is the most recent file?
Edit: Here are the contents of my source folder:
myBatchFile.bat
newest.txt
oldest.txt
second.txt
Of the *.txt files, newest.txt has the most recent modified date. Of all of the files regardless of extension, myBatchFile.bat has the most recent modified date given that I keep making edits to it to try to get it to work.
Edit #2: Here's a screenshot of my command window after running the first command above. This shows that all of the files in my source folder are copied when I only expect the newest file to be copied.
I'd use dir /b /o:-d /a:-d *.*, so the items are sorted by date (newest first) and directories are excluded. Otherwise the sort order is not clear, and directories like . (current) or .. (parent) might be returned unintentionally.
Instead of %%G I recommend using "%%~fG" to provide the full path, surrounded by doublequotes. Also the destination path should be enclosed in "" to avoid troubles with whitespaces.
The FOR /F should be changed to "delims=" in case the file name starts with a space (which I think is valid in Windows). "tokens=*" removed them.
Furthermore, I'd put parenthesis () around the code after do (so it is guaranteed and obvious that both commands move and exit /b are part of the loop context).
So all in all this leads to the following code:
FOR /F "delims=" %%G IN ('dir /b /o:-d /a:-d *.*') DO (move "%%~fG" "C:\Users\jrobinson\Desktop\" & exit /b)
Since the newest file is enumerated first and the for body contains exit /b (exit batch file), only that file is moved.
If you need to execute some other code after this line, replace exit /b by goto :SKIP (or any other valid label), and state the label (:SKIP) immediately after the FOR command block.
If the batch script containing the code herein is located in its working directory, moving it (in case it is the newest file) most likely results in unexpected behaviour. You can exclude the batch script itself by filtering it out using find like this:
FOR /F "delims=" %%G IN ('dir /b /o:-d /a:-d *.* ^| find /v /i "%~nx0"') DO (move "%%~fG" "C:\Users\jrobinson\Desktop\" & exit /b)
%~nx0 therein expands to the file name and extension of this script (see call /?).
I'm not sure I believe what you say. Because when I type the same command, is a file that I see first followed by the PAUSE command (or exit)
FOR /F "tokens=*" %G IN ('dir /b *.*') DO #echo %G & pause
So it always goes first action on the first file and the script will stop.
See this 5 secs gifv: http://i.imgur.com/kyHdN1Y.gifv with the following code:
#echo off
if exist ..\destination-test-folder\nul rd /s /q ..\destination-test-folder
if not exist ..\destination-test-folder\nul md ..\destination-test-folder
copy nul newest.txt>nul
copy nul oldest.txt>nul
copy nul second.txt>nul
dir /b .
pause>nul
echo: &echo For loop command: &echo:
for /f "tokens=*" %%g in ('dir /b "*.*"') do if "%%g" neq "%~nx0" move %%g ..\destination-test-folder>nul & echo pause is stated after each iteration & echo 1 file(s) moved. &pause>nul
echo: &echo list destination:
dir /b "..\destination-test-folder" &echo: &echo list source: &echo:
dir /b .
Just wanted to say thanks person: aschipfl
You are my hero.
here is the command I used to move all read only files to a sub folder "temp"
md temp
FOR /F "delims=" %%G IN ('dir /b /o:-d /a:R *.*') DO (move "%%~fG" "temp" )

windows 7 bat file leaves out parts of the command

I made a batch file with one command in it so that i dont have to remember the code. thought it would be simple however the code that it prints out when running it is not the code that is in the file. heres the only line in the file
for /f "tokens=*" %f in ('dir /a:-D /s /b') do move "%f" .
I have run this code in the command prompt and it does what i want it to however when i put it in a batch file and run it this the code that is read by the cmd
C:\Users\Erik\Desktop\google music backup>movefromsubfolders
-D was unexpected at this time.
C:\Users\Erik\Desktop\google music backup>for /f "tokens=*" -D /s /b') do move "f" .
why is it screwing everything up? This is the first bat file i have ever attempted to write so i could possibly be doing something stupid
you need double % when used in batch:
for /f "tokens=*" %%f in ('dir /a:-D /s /b') do move "%%f"

copy the recently modified file from source to destination in Batch script

How to copy the recently modified file from source to destination.
Constraint: All the files starting with same name in the source folder.
Example: Source - C:\Source and is having files like sys1239_5241.KNL, sys1234_8741.KNL
So how to copy latest modified files in batch file and modification will happen in minutes not in dates.
for /f "delims=" %%i in ('dir /b /a-d /od "C:\Source\*.KNL"') do set "LatestModifiedFile=%%~i"
echo copy "C:\Source\%LatestModifiedFile%" "X:\destination\path"
..remove echo if it looks good.
The following works well.
for /f "delims=" %%i in ('dir /b /a-d /od "C:\Teste_1\*"') do set "LatestModifiedFile=%%~i"
copy "C:\Teste_1\%LatestModifiedFile%" "C:\Teste_2\"
pause

Get name of last created folder on windows command line

Is it possible to get the name of the last created folder in a variable on the windows command line?
Preferably natively, without using Cygwin etc. What I'm looking for is to run some command/batch script which gives me the LastCreatedDir for the path in which I currently am
from a batch file:
#echo off
FOR /F "delims=" %%G IN ('dir /O:-D /A:D /T:c /B') DO (
#set yourvariable=%%G
exit /b
)

Resources