Small program help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
homeScape
Posts: 4
Joined: 12 Feb 2015 19:24

Small program help

#1 Post by homeScape » 12 Feb 2015 19:32

HI everyone,

I need some help with programming a small script. I recently had some problems with the removal of a file with a very long name, the solution was the "rmdir /s /q <dir>" command.

For future use i was planning to write a very small script that would let me click a icon on my desktop, then ask me for the <dir> and whgen i press enter it will remove the folder/file.

However i cant get the command prompt to ask me for the <dir> input, it tells me the folder hasnt been found (when i dont give one as input to start the script with) and when i make use of the pause command the command will end up being unused and i have to re-type it in order to remove the file/folder.


Is there an easy way to set-up somthing like:

---------

Folder/file removing tool, input file/folder location.
<user input>

-user puts in file location and hits enter

File(s) removed


----------


Greetings,

Tim

penpen
Expert
Posts: 1996
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Small program help

#2 Post by penpen » 12 Feb 2015 22:37

This "folderFileRemovingTool.bat" (placed in the SendTo Folder) might help you:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
:: you may want to edit the Volume variable to an unused volume
set "Volume=Z:"
pushd "%~dp1"
subst %Volume% "%~dp1."
%Volume%
call;
>nul (2>nul dir "%~nx1\.")
if errorLevel 1 (echo(del "%~nx1"
) else echo(rd "%~nx1"
%HOMEDRIVE%
subst /D %Volume%
popd
endlocal

pause
pause
You may need to use anothe unused volume descriptor (actually Z:).
Just right-click the file / directory to delete and choose SendTo->"folderFileRemovingTool.bat" (you may use a shorter name instead).
Actually it only displays "del <file>" or "rd <directory>". If this is what you need, just remove the two "echo(" and the two "pause"s.

penpen

homeScape
Posts: 4
Joined: 12 Feb 2015 19:24

Re: Small program help

#3 Post by homeScape » 13 Feb 2015 05:51

What exacly do you mean with the SendTo folder?

Tim

penpen
Expert
Posts: 1996
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Small program help

#4 Post by penpen » 13 Feb 2015 08:40

Files added to the (hidden) Folder "%USERPROFILE%\SendTo" appear within the context sub menu "Send To" (this path may vary on different windows versions):
http://www.howtogeek.com/howto/windows-7/stupid-geek-tricks-secret-items-on-the-windows-7-send-to-menu/

penpen

homeScape
Posts: 4
Joined: 12 Feb 2015 19:24

Re: Small program help

#5 Post by homeScape » 13 Feb 2015 08:45

Ive pasted the file in there, when i copy an file to the program it tells me to press any key to contunue but after that nothing happens with the file?

What am i doing wrong?

Tim

penpen
Expert
Posts: 1996
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Small program help

#6 Post by penpen » 13 Feb 2015 10:58

This program is actually only echoing the commands to let you check if it is what you need.
If this volume descriptor "Z:" is in use, then you should change the "set 'Volume=Z:"' line (to a drive letter that is not in use).
If you want to remove the files/folders using the displayed commands, then change:
'echo(del "%~nx1"' to 'del "%~nx1"', and
'echo(rd "%~nx1"' to 'rd "%~nx1"'
and remove the two 'pause' lines:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
:: you may want to edit the Volume variable to an unused volume
set "Volume=Z:"
pushd "%~dp1"
subst %Volume% "%~dp1."
%Volume%
call;
>nul (2>nul dir "%~nx1\.")
if errorLevel 1 (del "%~nx1"
) else rd "%~nx1"
%HOMEDRIVE%
subst /D %Volume%
popd
endlocal
You may want to use additional parameters; for more infos type 'help rd', and 'help del' (without the single quotes) into the command shell (cmd.exe).

penpen

homeScape
Posts: 4
Joined: 12 Feb 2015 19:24

Re: Small program help

#7 Post by homeScape » 13 Feb 2015 13:29

Cool, works like a charm :)

Thanks a bunch!

Tim

Post Reply