1.

Solve : select a file with command for?

Answer»

hello watcher

i don't know what code i need to use here, hopely you guys can help me.
i got this code and i not realy understand the "for" command
so hopely somebody can help me

code i already got:
Quote

dir %userprofile%\Downloads /O:-D /B>%appdata%\.minecraft\accounts\downloads.txt
for /f "Delims=1" %%e in (%appdata%\.minecraft\accounts\downloads.txt) do (

set mineshafter_loc=%%e

)

the problem is, i did something frong at line 2
the downloads.txt file looks like this at my pc

Quote
craftbukkit-1.4.5-R1.0 (3).jar
SBTA_PCDRV1_WIN8_LD_1_01_0001.exe
technic-launcher-0.5.4.8.zip
TechnicLauncher.exe
Technic Launcher (1).jar
Minecraft Tekkit.rar
craftbukkit-1.4.5-R1.0 (1).jar
craftbukkit-1.4.5-R1.0.jar
Kapitel 4 Gesundheit.docx
minecraft (2).jar
Minecraft_Server (6).exe
minecraft (1).jar
Minecraft_Server (5).exe
NEDH3Dstudiewijzer periode 2 2012-2013.doc
Speedtest_TuneUpUtilities2013_nl-NL (1).exe
Agressie in de sport nederlands (2).docx
FI8903W.04W.05W-11.35.2.46 (1).zip
FI8903W.04W.05W-11.35.2.46.zip
FI8903W.04W.05W-11.25.2.46.zip
FI9820W-3.2.6.1.1-20120807.zip
Agressie in de sport nederlands (1).docx
IPCamSetup.exe
IP Camera Tool Mac MJPEG.zip
LB Photo Realism x256 8.0.0.zip
FI8903-04-fw11.15.1.42.zip
2[1].4.8.9.bin
foscam.zip
FI8904W_firm_11_15_1_46.zip
FI8903-04w-fw11.15.1.46.zip
FI8903-04-fw11.15.2.17.zip
Agressie in de sport nederlands.docx
another title (1).docx
H-app-33.1.1.35.bin
H-app-32.0.0.30.bin
F-app-7.5.3.46.bin
F-app-7.5.3.46_ATZ.bin
another title.docx
BP 1.1.0 Patch only.rar
SkypeSetup.exe
SkypeSetupFull.exe
Ethos LP-ep214.zip
solutions 3 H3 woorden A en B (1).xls
solutions 3 H3 woorden A en B.xls
Speedtest_TuneUpUtilities2013_nl-NL.exe
World!.rar
HOLY *censored*.png
2012-11-30_09.37.23.png
Ideeen Survival.txt
PS_AIO_02_USW_Full_Win_WW_130_140.exe
WoT_internet_install_eu.exe
WoT_internet_install_na.exe
worldedit-5.4.5.zip
craftbukkit-1.4.5-R0.2.jar
Terraria v.1.1.2.rar
Minecraft_Server (4).exe
kering project sketchup.skp
WP_000619.jpg
oCd-pack-14-by-disco.zip
PS3-64.zip
DS3 Tool.lnk
Minecraft_Server (3).exe
Progress Bar Code.txt
master.bat
vcredist_x86 (1).exe
vcredist_x86.exe
commandblocksigns (1).py
commandblocksigns.py
2012117_trainingsschema_officieel 2012-2013.xlsx
SethBling's Redstone Challenge Level 20 Lukelumia800.zip
sethbling_s_redstone_challenge.zip
CS6-AMTLIB-32-bit.rar
show_ads.js
Ghost.jar
InvTweaks-1.44-1.4.2.zip
ModLoader.zip
Stunzle v1.6 by Zinic.rar
ENG klas3 leesdos.doc
Book report year 3.doc
lastlogin (6) (1)
lastlogin (6)
lastlogin (5)
lastlogin (4)
lastlogin (3)
lastlogin (2)
lastlogin (1)
lastlogin (7)
lastlogin
Minecraft codes Generator.exe
CMD Accounts.zip
20100824mmp410nl.pdf
solutions 3 H2 woorden.xls
solutions 3 H2 woorden.oh4
craftbukkit-1.4.2-R0.2.jar
Essentials-2.9.4.zip
craftbukkit-1.4.2-R0.1.jar
worldedit-5.4.3.zip
craftbukkit-1.3.2-R3.0.jar
TooManyItems2012_10_28_1.4.2.zip
Minecraft_Server (2).exe
Kapitel 2 Total technisch.docx
Dropbox 1.4.20.exe
Minecraft_Server (1).exe
SimpleGameExtra.zip
The Walls 2 - PvP Survival - v1.00.zip
Minecraft_Server.exe
registrybooster (1).exe
registrybooster.exe
FlashDevelop-4.0.0-Beta2.exe
wallpaper_windows-7_animaatjes-36.jpg
wallpaper_windows-7_animaatjes-32.jpg
wallpaper_windows-7_animaatjes-30.jpg
ashbal-windows-7-wallpaper.jpg
world5.zip
A Puzzle for logan_ABC.doc
A Puzzle for logan.doc
PasswordProtect.jar
DOSBox0.74-win32-installer.exe
SteamInstall.msi
PasswordSafe.jar
world1.zip
world10.zip
sysbord151.zip
technic-launcher.jar
SinglePlayerCommands-MC1.3.2_V4.1.jar
Tut Rig For Download.c4d
Sentry 1.0.2.zip
Premium Minecraft Account Generator.rar
Minecraft.exe
Technic Launcher.jar
PanoramaKit v2.3.2.zip
MC 1.3.2 - Smart Moving 10.0.zip
jre-7u6-windows-x64 (2).exe
Mineshafter-proxy (1).jar
JavaSetup7u6.exe
jre-7u6-windows-x64 (1).exe
jre-7u6-windows-x64.exe
Checkpoints.zip
videoconverter_free.exe
jre-7u5-windows-x64.exe
Templates.properties
radmin34nl
radmin34nl.zip
mysql-connector-net-6.2.3 (2).zip
wiredcms.zip
ilost_catalogfix.zip
uberdb.sql
uberServer - Meth0d and iJakey.rar
R63_Remixed_Pack_rar.exe
dotNetFx40_Full_setup.exe
vcs_web.exe
xampp-win32-1.7.7-VC9-installer.exe
mysql-connector-net-6.2.3 (1).zip
mysql-connector-net-6.2.3.zip
TeamSpeak3-Client-win64-3.0.6.exe
NoLagg_v1.82.zip
vlc-2.0.1-win32.exe
NationaleVacaturebank_nl - sollicitatie vacature - Claimbehandelaar AOV.eml
cv Marianne Smitsloo.doc
cv Marianne.doc
craftbukkit-1.2.3-R0.1.jar
Mineshafter-proxy.jar
jre-6u31-windows-x64.exe
admin forcer.exe.eb9mskf.partial
DivXInstaller (1).exe
Mineshafter-proxy.exe
CNET_TechTracker_2_1_0_69_Setup.exe
imgconvert.exe
AdobeDownloadAssistant.exe
free_flash-intro-templates_y4yplyr7vonm1lar.zip
DivXInstaller.exe
SolveigMM_HyperCam_3_3_1111_16.exe
ImageIconConverter.exe
minecraft_modified.jar
minecraft.jar
RE_ Verzuimcoach _ casemanager _part-time_full-time.zip
GoogleSketchUpWNL.exe
blender-2.60a-release-windows32.exe
Blend_Trial_en.exe
FreeMouseAutoClickerSetup.exe
SolveigMM_HyperCam_3_3_1109_27.exe
Google_Gadget_NL.gadget
Teletekst.gadget
FlvPlayerSetup.exe
Spaans H1 moeilijk.mp3
wrts (2).mp3
Gente Joven HSt 1. ¶õ.9[1]. Nos vemos en el chat
HC2Setup.exe
jre-6u26-windows-i586-iftw.exe

i only want to copy the first file out this list in my batch file

hopely you guys can ride a code that works good
-lukeCode: [Select]@echo off
for /f "delims=" %%e in ( ' type "%appdata%\.minecraft\accounts\downloads.txt" ' ) do (
copy /b "%%e" "e:\target folder\"
goto :done
)
:doneJust for learning experience: 'set /p VARIABLE =So (using foxidrive's copy example) we can use:
Code: [Select]@echo off

REM This is where we gather the first line, setting it equal to the variable %a% (found right before the "=")
set /p a=<"%appdata%\.minecraft\accounts\downloads.txt"

REM Here we copy the file (I believe it has to be in the current directory [%appdata%\.minecraft\accounts\]) to target folder and or drive
copy /b "%a%" "e:\target folder\"

REM This is to pause the script when complete. Depending on the versions of windows you are using, it may do this automatically.
REM I know that Windows 7 closes the window almost instantly before ending, whereas Windows XP will wait.
pause>nul

REM If you are using Windows XP and you wish to have the file close when finished, end your script with the 'exit' command.



The 'for /f' command (the one used in your script) allows cmd to INTERPRET, line by line, a string of text, text file, or a command output. So say we wish to grab the last modification date on a folder (listed on the far left when using 'dir'). We could use 'for /f' to separate the output into chunks.
Code: [Select]for /f "tokens=1,5 delims= " %%A in ('dir') do (
if "%%B"=="DIRECTORY NAME" set lastModified=%%A
)
What this basically tells cmd, is that it wants to check the output of 'dir', and read it line by line. Because 'dir' formats it's information:
DATE TIME PM NAME
DATE TIME AM NAME
we can use "delims= " to separate the lines at each space. The other thing inside the quotation marks is "Tokens=1,5". This tells cmd to only look at the first and fifth segment (after the line is separated by spaces). This will get us only the date and name. The 'if' statement is thrown in to further sift through the results. It checks if the 2nd used token (#5) is the same as the desired directory, and if so sets the veritable %lastModified% to the first used token (#1).

This can be used with any command (enclosed in single quotes), string (enclosed in double quotes), or text file (is not enclosed). though it always reads only 1 line.

I hope this helps you understand 'for' a little better. It can be somewhat confusing at times.


EDIT: Be warned that the 'for /f' example only works if there are no spaces in the folder names.Thank you very much for the code foxidrive, the finaly code i used is:

Quote
@echo off
for /f "delims=" %%e in ( ' type "%appdata%\.minecraft\accounts\downloads.txt" ' ) do (
set test=%%e
goto :done
)
:done
echo %test%
pause

and thank you Lemonilla,
i understand it a little bit more

bye and thank you


Discussion

No Comment Found