Solved Why does the move command not work a i second /i time?

August 7, 2015 at 23:15:07
Specs: Windows 7
What the program below is going to do is essentially lock the Misc.ink and or Shortcut with a simple push of a button by moving it away from the desktop and prying eyes.

THE PROBLEM

seems to appear when I try to toggle the Misc.ink back on to the desktop. It just stays where it is, I have tried putting it in front of the code that move it to documents but it still does not work. shouldent it just be the move away command but flipped

The trouble code is at the bottom and don't worry about how it looks on here because its quite nice in command prompt.

@echo off

:Folder_Locker

if exist "C:\Users\User\Desktop\Misc.lnk" set Status=Unlocked

if not exist "C:\Users\User\Desktop\Misc.lnk" set Status=locked

Cls
echo ============================================================
echo = =
echo = Folder Locker =
echo = =
echo ============================================================
echo = Please Type In The Password To Unlock\Lock Folder =
echo = = = = = = = = = = = = = = == = = = = = = = = = = = = = = =
echo = The Folder Is Currently == %Status%
echo = = = = = = = = = = = = = = == = = = = = = = = = = = = = = =
echo = Would You Like To Toggle Misc.ink? =
echo ============================================================
set /p Input=

if %Input%== Yes goto Toggle

if %Input%== yes goto Toggle

if %Input%== Y goto Toggle

if %Input%== y goto Toggle

end

:Toggle

if not exist "C:\Users\User\Desktop\Misc.lnk" move "C:\Users\User\Documents\Misc\Misc.ink" "C:\Users\User\Desktop"

if exist "C:\Users\User\Desktop\Misc.lnk" move "C:\Users\User\Desktop\Misc.lnk" "C:\Users\User\Documents\Misc"

goto Folder_Locker


See More: Why does the move command not work a i second /i time?

Report •


✔ Best Answer
August 9, 2015 at 19:43:41
Well, the main thing I see with the text-file approach is that you are appending each time, instead of a "straight write". That's fine, as long as whatever process knows to only check the last line of the textfile for the status, and ignore all preceding lines.
">>" means "append", ">" means write-over ie straigh-write which keeps your status-text-file as always only one line.
My script is fairly simple, so I don't know what items to explain. %desktop% is assigned from a system-level variable that points to the current user's profile (see output of: SET or SET U). Script calls toggle once to get status (when there's no element #1), then a second time to toggle the status (when element #1 is "Y" or "y" or "yes" or "Yes" or "YES" etc) (see: IF /? /I ignore-case option which saves a lot of extra coding). %offline% is anywhere you want to store the link when it's not on the desktop. Anything else just ask with specifics, I will be happy to excplicate.

message edited by nbrane



#1
August 7, 2015 at 23:17:04
Pardon the unnecessary "i" in the title, I wanted to see if italics worked in the title.

Report •

#2
August 8, 2015 at 00:50:10
Think about what happens when the file is in the C:\Users\User\Documents directory.

The first "if" statement correctly moves it to the desktop. Now we reach the second "if" statement. It tests if the file exists on the Desktop - yes, now it does. It then moves it back to the Documents directory.


Report •

#3
August 8, 2015 at 01:24:00
Yep. Funny how that works.

If the purpose is to allow only those with the password to run the link, which is what it seems:

::====== script starts here ===============
::
:: smev1.bat 2015-08-08 15:20:04.03
@echo off & setLocal enableDELAYedeXpansioN

set/p PW=password?
if !PW! equ abc start some.URL

::====== script ends here =================

=====================

M2 Get custom script or take private lessons


Report •

Related Solutions

#4
August 8, 2015 at 17:17:17
The commands were flipped before and it still had the same outcome, but ill come up with a workaround for the matter and see if that is indeed the problem.

Report •

#5
August 8, 2015 at 17:39:01
Great, my work around is not working... what I`m trying to do is if the target (target referring to Misc.lnk) is on my desktop, print 0 in a text document, and if it is in documents and or locked state, then it would print a 1 but NOPE denied for a reason that evades me. Could you guys help with this also?


:Toggle

cd C:\Users\User\Documents\Misc\Creations\Program_Stats

if exist "C:\Users\User\Documents\Misc.lnk" @echo 1 >>ToggleLock.txt
if exist "C:\Users\User\Desktop\Misc.lnk" @echo 0 >>ToggleLock.txt

goto Folder_Locker


Report •

#6
August 9, 2015 at 01:05:22
This seemed to work in tests:
::====== begin batchscript SMEV5..bat
@ECHO OFF & SETLOCAL
set lnk=hello.bat.lnk
set dsktop=%userprofile%\desktop
set offline=c:\temp
call :toggle
echo = Folder Locker =
echo = =
echo ============================================================
echo = Please Type In The Password To Unlock\Lock Folder =
echo = = = = = = = = = = = = = = == = = = = = = = = = = = = = = =
echo = The Folder Is Currently == %Status%
echo = = = = = = = = = = = = = = == = = = = = = = = = = = = = = =
echo = Would You Like To Toggle Misc.ink? =
echo ============================================================

set /p Input=

if /i %Input%==Yes call :Toggle Y

if /i %Input%==Y call :Toggle Y

goto :eof

:Toggle


if exist "%dsktop%\%lnk%" (
set status=unlocked
if "%1" equ "" goto :eof
echo EXISTING ON DESKTOP moving offline
move "%dsktop%\%lnk%" "%offline%"
) else (
set status=locked
if "%1" equ "" goto :eof
ECHO NOT ON DESKTOP moving online
if exist "%offline%\%lnk%" move "%offline%\%lnk%" "%dsktop%\%lnk%"
)
goto :eof

REM goto Folder_Locker


Report •

#7
August 9, 2015 at 14:05:33
I don't quite understand the code, I only know the basics of dos, as you can probably see from my caveman like code.
All in all could you ether explain the code or try to help with the text document variable thing?

Report •

#8
August 9, 2015 at 19:43:41
✔ Best Answer
Well, the main thing I see with the text-file approach is that you are appending each time, instead of a "straight write". That's fine, as long as whatever process knows to only check the last line of the textfile for the status, and ignore all preceding lines.
">>" means "append", ">" means write-over ie straigh-write which keeps your status-text-file as always only one line.
My script is fairly simple, so I don't know what items to explain. %desktop% is assigned from a system-level variable that points to the current user's profile (see output of: SET or SET U). Script calls toggle once to get status (when there's no element #1), then a second time to toggle the status (when element #1 is "Y" or "y" or "yes" or "Yes" or "YES" etc) (see: IF /? /I ignore-case option which saves a lot of extra coding). %offline% is anywhere you want to store the link when it's not on the desktop. Anything else just ask with specifics, I will be happy to excplicate.

message edited by nbrane


Report •

Ask Question