Jump to content

DosCode

Member
  • Posts

    46
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    Czech Republic

Everything posted by DosCode

  1. bphlpt I need no reply for that pdf convertion. I already have my solution. "I still would be interested in seeing your COMPLETE solution, since you say you have one" I should repeat that I use more scripts, not one complete script. I download files from more pages and servers. Check the last post on page 2. The Poland page, this is the last task I did. Before, I did this page: My link and I included code to determine if the number has decimal. Because the search process could take too long if I have files like "ENR 1.72 ...", "ENR 1.7 ...", "ENR 10 ..." .... I search for "ENR "+digit+space... and that caused I would looked for more files then I want. I really don't know if to send here the script, that already serve to different purpose - goal has change a little bit for different task. "I'm always interested in learning new CMD script tricks and I've learned they can come from unlikely sources. So, will you share?" I think I could send you all my scripts on your email if you want. But they are really individual. I for example have wget script and I always rewrite the url address from where I download or I change the -A argument, according my conditions. The poland files I downloaded with downthemall - I had some problem, that the wget did not worked for this server. "Hopefully they at least say thanks, and most do." Man, If you would know me, you would know that I say always thanks in my life even if it is not necessary. "Apparently you are more interested in learning how rather than the speed of getting to the solution, and that is admirable." Yeah, my approch is different. I am used to when I learn something it consumes really huge quantums of time. Layout the complete task Provide the type of input data you will be dealing with Describe the output you wish - exactly - and sometimes even say why Describe the steps you want to learn how to do in order to get from input to output Describing things is something mystical for me. But I really sometimes am lost on this thread, because all the posts seems soooo long.
  2. Your answer shows you lie. I did my job what I needed. It does not mind that my code is not according your ideas. Please don't say I learned nothing or you are liar! I have many bad habits and in my country we say "You cannot learn an old dog dancing!".
  3. You are moderator, you know very well that I gave thank to all at 23 February 2012 - 05:24 PM! And "failure to listen, learn, understand" ... this is not my failure but natural part of my character, this is me. I confess, I have no problem with acceptation of my being!
  4. No, this Forums Members as good as wrote it for you but you don't need it, it serves no purpose. This newer single script negates its use!!! You are the only person running a script to change a file name before running another script to change the same file name, that can only be your fault. As the topic is titled, I was looking for CMD script. And in the time when I didn't find CMD solution here I was looking another way to get answer and to make my own script. This was before your solutions came here. I started to learn the CMD scripting as I have beed reffered to the links. So I don't know why you wonder what I rather decided to use my own script. It is still subject of my learning and I don't know what you don't understand when I say that I better like to do my own script to learn it ... than to use someone's code which is already done. Also somebody in this thread has written that THIS THREAD SERVES TO ALL. Then your assertion is not true, because other user's can use the different version of code (versions of other coders). Even me. I take this thread as a place of information where I can come back whenever. Whenever when I feel that I am stuck somewhere I can look how you did your code. So really don't understand where you see problem. Sorry for posting miss-clicking on incorrect button, so I posted the new question in the same thread.
  5. I tried to do some script to rename pdf files from this site: http://www.pl-vacc.org/pol3/files.php?d=maps&language=en @echo off setlocal EnableDelayedExpansion for %%P in (*.pdf) do ( set "pdfFile=%%P" set "htmlMask=info.htm" echo Testing "!pdfFile!": Looking in !htmlMask! for %%H in (!htmlMask!) do ( echo "%%H" set "pdf=%%P" set "source=%%H" call :JUMP ) ) ) ) :JUMP REM Get title for pdf from html file rem Process each line in %source% file: for /F "delims=" %%c in ('find /N "%pdf%" "%source%"') do ( set "line=%%c" REM Test if the line contains pdf file I look for: SET "pdfline=!line:%pdf%=!" if not "!pdfline!" == "!line!" ( cls SET "pdfline=!pdfline: = !" SET "pdfline=!pdfline:</a>= !" SET "pdfline=!pdfline:*>=!" SET "pdfline=!pdfline:*>=!" SET "pdfline=!pdfline:*>=!" SET "pdfline=!pdfline:*>=!" SET "title=!pdfline:*>=!" set "title=!title::=-!" set "title=!title:\=-!" set "title=!title:/=-!" set "title=!title:|=-!" set "title=!title:?=-!" set "title=!title:^==-!" set "title=!title:>=-!" set "title=!title:<=-!" ren "%%P" "!title!.pdf" ) ) This action was fast.
  6. I've written that already, but I will recall it to you. It is not a fault! I decided to rename the files (to remove prefix) before I have decided to write script that renames the files according html description.
  7. I just click it. It is more faster. I sometimes run cmd to console but there happens to me I forget to close it so I have 4 or 5 cmd consoles, so more windows opened makes it confusing to orientate so I like it to autoclose. I usually add a pause, but I it could be so that you could use in the code somewhere command to go to end of file. So I did not add it there. You seen that I used pause everywhere. Also I edited the previous post to you, also bad habit.
  8. This is my final solution. It takes cca 20 seconds to rename the files, maybe some of the solutions here mentioned by others could be faster. But I am satisfied, that it works. @echo off setlocal EnableDelayedExpansion for %%P in (*.pdf) do ( set "pdfFile=%%P" set htmlMask="GEN !pdfFile:~0,1! *.html" REM echo !htmlMask! echo Testing "!pdfFile!": Looking for !htmlMask! for %%H in (!htmlMask!) do ( echo "%%H" set "pdf=%%P" set "source=%%H" call :JUMP ) ) ) :JUMP REM Get title for pdf from html file rem Process each line in %source% file: for /F "usebackq delims=" %%c in ("%source%") do ( set "line=%%c" REM Test if the line contains pdf file I look for: SET "pdfline=!line:%pdf%=!" if not "!pdfline!" == "!line!" ( REM Test if the pdfline contains tag b if not "!pdfline:*><b>=!" == "!pdfline!" ( cls set "tag=!pdfline:<b>=$!" set "tag=!tag:</b>=$!" for /F "tokens=2 delims=$" %%b in ("!tag!") do set title=%%b set "title=!title::=-!" set "title=!title:\=-!" set "title=!title:/=-!" set "title=!title:|=-!" set "title=!title:?=-!" set "title=!title:GEN =!" echo Title found: "!title!" ren "%%P" "!title!.pdf" ) ) ) Finally I decided to remove the "GEN " prefix in title. Edit: I've made some edit of the code, because I found some lines that was unneccesary, but did not test it. I tested the code before and it was really not good, so I made some changes in the code in my PC, but do not give it here, because the circumstances has changed.
  9. Well, then you know better what it does than me and I need not to tell you anything. I checked the code at the start and thought the loop looks for pdfs in html. That's why I asked you if my assumption is right, but you did not answer that question. And I run your code, but the console closed so I see no output. Then if you understand what I wanted to reach, I need not to tell you anything. jaclaz, isn't that what you wanted to hear? I thought your solution simple doesn't work. You don't understand my habits. I usually give thanx when I found some solution for my problem or when I finish my discussion in the thread. So that you don't receive thank doesn't mean you wouldn't receive it later.
  10. This is a sub-function. This tells me that you did not set %pdf% file to search for (in the html file). What do you try to do in the loop? Do you try to find all pfds that are in html document? Because what I tried to do was to find one certain pdf, that is in the html document. You can start either by searching pdfs, so you should set the name of pdf file. This instructs where the anchor and title is placed. But as a complete code, that should find all pdfs and for each pdf to open the html document which is associated with the pdf. So if your code as sub-function should work fine, you must define pdf file you look for. Late answer to bphlpt. „There are definitely cases, IMO, where CMD script is faster and more flexible than other options. “ That is not the reason why I’m interested in CMD. It is much simpler to me against VBS. VBS is Object orientated language and so is more harder to learn. CMD with connection with gnuwin results in something what seems to me similar to bash. So that is the reason for been it favourite for me. „CoffeeFiend and I don't need to continue on. “ I have finished so I also need not to continue. „Our two posts do not distract from your overall goal as much as your posts which have been scattered over multiple threads and have yet to come up with a working solution. “ So to you. You have seen I was distracted enough to overlooked two post. I explained that before. „You have been asking about bits and pieces for a week now, and we didn't even know what your overall goal was until 18 hours ago. “ If I would told you what was my overall goal, than I would spent a lot of time with long time explaining and I would not get answers to my original questions which were the individual solutions of certain situations. I did not want you just all solved instead me. The second point is that is was simpler to me just to make what I want by myself, and then to paste the code and wait your reactions. This is just the way of demonstration. That's better then lots of words. Since the start I see I have learned something, I moved from nothing to something. And that’s what I personally feel to be satisfying. Also I see no reason why I should spend 24 hours 7 days week on forum, I don't mind this took more then week. So maybe you had wait, but I see no problem in it. Late answer to Aacini's code Yes, works but there should be some condition, because it returns title "" and twice title ,,GEN 0.1 Preface", but you need not to do it, because I have already my code completed, so as you could see in the debuger's code version. Replay to Yzöwl's CMD code This script prints REN "gen_0_3.pdf" "GEN 0.3 Record of AIP Supplements.pdf" REN "gen_2_1.pdf" "GEN 2.1 Measuring System, Aircraft Markings, Holidays.pdf" REN "gen_4_1.pdf" "GEN 4.1 Charges for Aerodromes and Heliports.pdf" REN "gen_4_2.pdf" "GEN 4.2 Charges for Air Navigation Services.pdf" Press any key to continue... So pdfs staring by digit are not listed. Replay to CoffeeFiend I cursorily searched internet for gnuwin PowerShell binaries but did not find so did not test your code.
  11. I thank to all who have brought some solution and some code here. Sure. One day more of patience for today I hadn't time to devote to the code. bphlpt - yeah, it is the goal, to download files and rename them. But I personally more like individual scripts, every one servers to its own purpose. Because there are different situations, when I download different "folders" of pdf documents. So some files need to be moved, some need to be renamed, some need html documentation, some need no documentation. So this is something individual according what I download. I would be more glad if I would need not these scripts, but I don't know about such browser addon, that would enable you to download more levels of documents, create folders and move documents to folders according organization on html page, and rename folders by chapters or by their purpose and title in html page.
  12. jaclaz: Yes, I overlooked. Maybe because when I came to PC, I have seen the CoffeeFiend's reply about VBS and I did not read it, I just did not see there is one or two posts above it. Yours posts have been just between CoffeeFriend and bphlpt post about VBS, that I did not concentrated my attention to. The post are long on my screen taking much of place. Not simple to orientate. I guess the fault is on design of this site because the left column is too wide! I will try to have some time tomorrow. Now time to sleep.
  13. Oh, I have overlooked the post from Aacini (and more posts at that time), and I did not see the error in his code, because I did not test his code. Sorry for all. But never mind you came here, Aacini, thanks for your try. Problem is that the tag a alway has attributes. But your solution is inspirative to me. I could try use regex for this. But have no time to think about it now. What about to try findstr regex like <a *>.*</a> but to add there ungreedy option?
  14. Name of the topic is "renaming files in CMD scripts". I believe his code is fine and works. But I just want CMD solution or CMD+gnuwin. I originally did not know that I would rename the files by html title. This decision I did later. I still can remove the non-willing prefix by script.
  15. Yzöwl: Sure findstr /C:"<a>" will fail. This tag has no sense. Because a tag always has some attributes. bphlpt: Well, I was worried somebody could to abuse the link downloading big amout of files, because if more people would that do it at same time, I think that could slow down or maybe overload the server? Don't know. When I downloaded the files it took me 1 or three minutes, but I downloaded more files not just these ones and I did that by parts. I don't need the VB script even it can be good. Realize how much time I spent by learning the cmd things, even I am pretty bored (not in bad meaning, rather "lazy") and not devoting so much time to this job as I could. So now I send just what I have in my PC and going to have some rest. You can repair me, if you see some mistakes in my code. @echo off setlocal EnableDelayedExpansion for %%P in (*.pdf) do ( set "pdfFile=%%P" set htmlMask="GEN !pdfFile:~0,1! *.html" REM echo !htmlMask! echo Testing "!pdfFile!": Looking for !htmlMask! set "found=" for %%H in (!htmlMask!) do ( set found=1 echo "%%H" for /f "delims=" %%b in ('find /i "<title>" ^< "%%H"') do ( set "pdf=%%P" set "source=%%H" set "var=%%b" call :JUMP ) REM do whatever you need to do with the %%P pdf file and %%H html file ) REM if not defined found echo NOT FOUND ) ) echo done - check tempren.bat ::goto :EOF :JUMP REM Get title for pdf from html file set "source=%source%" set "pdf=%pdf%" rem Process each line in %source% file: for /F "usebackq delims=" %%c in ("%source%") do ( set "line=%%c" REM Test if the line contains pdf file I look for: SET "pdfline=!line:%pdf%=!" if not "!pdfline!" == "!line!" ( REM Test if the pdfline contains tag b if not "!pdfline:*><b>=!" == "!pdfline!" ( cls set "tag=!pdfline:<b>=$!" set "tag=!tag:</b>=$!" for /F "tokens=2 delims=$" %%b in ("!tag!") do set title=%%b set "title=!title::=-!" set "title=!title:\=-!" set "title=!title:/=-!" set "title=!title:|=-!" set "title=!title:?=-!" echo Title found: "!title!" pause ) ) ) I will finish it later :-) I'm so lazy...
  16. It is solution for sub function. I guess you tested the Visual Basic script from the guy that has written here and admin has blocked your access. I did not say go and download/overload their server. If anybody did so, his own fault. I am not glad of this happen. But to be exact, I did not test or checked that VB scipt, I just guess there were some instructions to download the pdf files. I will paste here my code after your answer.
  17. Check my last post. I edited it, there is the code that could be implemented to the code I posted before, yet one little change need to be done.
  18. Here I am so far: @echo off setlocal EnableDelayedExpansion set "source=GEN 0 GENERAL.html" set "pdf=0_1_en.pdf" echo In file:%source% echo Look for anchor:%pdf% rem Process each line in %source% file: for /F "usebackq delims=" %%c in ("%source%") do ( set "line=%%c" REM Test if the line contains pdf file I look for: SET "pdfline=!line:%pdf%=!" if not "!pdfline!" == "!line!" ( cls echo Line: !line! REM Test if the pdfline contains tag b if not "!pdfline:*><b>=!" == "!pdfline!" ( cls echo I HAVE IT! set "tag=!pdfline:<b>=$!" set "tag=!tag:</b>=$!" for /F "tokens=2 delims=$" %%b in ("!tag!") do set title=%%b echo Title found: "!title!" pause ) ) ) pause There is still more ways how to do this part, but I think now is your turn.
  19. I don't download the document manually, I have script for CMD and wget. I also rename the files and I work with all informations from the site with CMD. I simply want batch file to be the main execution file. The files that I have in my PC are renamed by script. So when I downloaded EK_GEN_0_1_en.pdf I renamed it to 0_1_en.pdf, When I downloaded gen_4_2.pdf I renamed it to 4_2.pdf I want to do it in way which I like and which is close to what I already know. I don't want use VB or something which is too far of what I learned till now.
  20. It is as you say "one off solution with very specific criteria". All pdf files are in one folder. And I want to rename them according the title, which is enclosed in their links. I can use CMD which I prefer because I have windows and I learn it, and try it to be independent on gnuwin32, but if it is necessary, or optional, I don't mind to use gnuwin32 programs. It is also interesting to know/learn how the grep or sed works. In bin folder have these programs installed: egrep.exe, fgrep.exe, find.exe, grep.exe, locate.exe, pcregrep.exe, pcretest.exe, sed.exe, xargs.exe. I solved more ways of working with these pdfs and htmls last days, but I would not call it project. They are just helping scripts, and I would like they to help me to save many work, if I am possible to understand them and edit them if necessary. I try to use the potential of CMD in my computer, which I did not know about before. Answer to your paragraph in italic. I know what is in the file because I checked it. But I can refer you if you want to check it online. Check this page here. If you click on one of the yellow folder icon, you will see the html file having the links to the pdfs I work with.
  21. Not good solution I tried to do. Here is the thing I wanted to do, in working script. @echo off SETLOCAL EnableDelayedExpansion for %%P in (*.pdf) do ( set "pdfFile=%%P" set htmlMask="GEN !pdfFile:~0,1! *.html" REM echo !htmlMask! echo( echo Testing "!pdfFile!": Looking for !htmlMask! set "found=" for %%H in (!htmlMask!) do ( set found=1 echo "%%H" for /f "delims=" %%b in ('find /i "<title>" ^< "%%H"') do ( set "pdf=%%P" set "source=%%H" set "var=%%b" call :JUMP ) REM do whatever you need to do with the %%P pdf file and %%H html file ) REM if not defined found echo NOT FOUND ) ) echo done - check tempren.bat ::goto :EOF :JUMP :: code I am working on.... I am going to do a search in html file %%H. There is some tag a in the html file, which includes %pdf% filename (without path). I would like to get the contents of this tag, including tag b, including title of the pdf file. The goal is to get the title for the pdf file to variable, so I can use it to rename the file. If the tag a includes image but no text like this <a pdffile link><img></a>, than skip this link. The link is on single line, so I could use grep.
  22. Till now I have this code: @echo off SETLOCAL EnableDelayedExpansion for /f "delims=" %%P in ('dir /b *.pdf') do ( SET "sPDFName=%%~nxP" echo "!sPDFName:~0,1!" IF "!sPDFName:~0,1!"=="1" (SET "sPDFName=!sPDFName:~0,1!") IF "!sPDFName:~0,1!"=="0" (SET "sPDFName=!sPDFName:~0,1!") SET tempStr="GEN !sPDFName!*.html" echo !tempStr! ::echo "!sPDFName!" for /f "delims=" %%H in ('dir /b *.html') do ( CALL SET substring=%%H:~!tempStr!%% echo Result:%substring% IF "%%substring%%"=="%%H" (echo %%H) ELSE (echo NOT FOUND) pause )) I am not sure with the CALL SET expression, it should return name of %%H if the file exists. If does not exist then should return null. Not positive result. Probably I have to remove quotes from !tempStr!, but did not succeed to do that. Expects you have files "0_1_en.pdf" and "GEN 0 GENERAL.html".
×
×
  • Create New...