How to browse for file (Win7/64bits) - windows

I need to quickly write a simple GUI over a command line application. Two steps are required:
Specify an input file path,
Specify an output file path (non existing)
I found out a previous post, however trying to get the above (1) to work seems like an insane task.
Indeed BrowseForFolder seems to only work in some weird cases, you can use BIF_BROWSEINCLUDEFILES for only *.pdf and/or *.txt (trial and errors). I can get an error if I select a *.dll and/or a *.jpg (don't ask).
So instead, I gave up this approach and followed another one, in this case (objIE.Document.all.FileSelect), only the name of the selected file is returned the path seems to be always set to "c:/fakepath" for some reason. So again I am missing the full path to be able to pass that to the command line app.
Is there any sane way (<10 lines of codes) to get (1) and (2) working on Win7/64bits (VBS, HTA...)?

Don't know if people are still interested in the BrowseForFolder file selection issue, but here's what I've found.
I had the same issue selecting files with BrowseForFolder using &H4000 / BIF_BROWSEINCLUDEFILES. I could get a return with .docx but not .doc files and as you say .pdf files.
For me .txt wouldn't return anything, as didn't WMI Backup .rec files that I needed for a script I'm writing, resulting in this error information:-
Error: Unspecified error
Code: 80004005
Source: (null)
After looking at other solutions I came back to this one as my preferred choice, plus it was doing my head in that it didn't want to work. So at the bitter end it seems to be this easy.
To get my .rec files recognized I add this to the registry:-
[HKEY_CLASSES_ROOT\.rec]
#="WMI.Backup"
[HKEY_CLASSES_ROOT\WMI.Backup]
#="WMI Backup"
"BrowseInPlace"="1"
To get .txt files recognized I add this to the registry:-
[HKEY_CLASSES_ROOT\txtfile]
"BrowseInPlace"="1"
So "BrowseInPlace"="1" seems to be the nugget.
Seems so unbelievably easy that I'm sure this solution is out there somewhere but I never came across it so thought I'd put it online.
I would be interested to find that it works for others as I fear that this issue may of sent me mad, still can't believe it seems to work.
Hope this helps.

Here are 3 different ways to do what you want:
http://www.robvanderwoude.com/vbstech_ui_fileopen.php

Related

Adding multiple files with one command

I tried to give a sample of a list of my titles. Here it is:
'197. Module Introduction.txt' '198. Our Starting Setup.txt' "199. What's So Complex About Forms.txt" '200. Dealing With Form Submission & Getting User Input Values.txt' '201. Adding Basic Validation.txt' '202. Providing Validation Feedback.txt' '203. Handling the "was touched" State.txt' '204. React To Lost Focus.txt' '205. Refactoring & Deriving States.txt' '206. Managing The Overall Form Validity.txt' 'Assignment 5: Time to Practice: Forms.txt' '207. Adding A Custom Input Hook.txt' '208. Re-Using The Custom Hook.txt' '209. A Challenge For You.txt' '210. Applying Our Hook & Knowledge To A New Form.txt' '211. Summary.txt' '212. Bonus: Using useReducer.txt' '213. Module Resources'.txt
All those titles were in a text file named lectures.txt.
I wanted to create a series of titled blank text files in a folder I had already created to receive them. Each text file should have the specific titles as in that example list. Ultimately I would be creating nearly 500 files, but all of them would have very specific meaningful titles.
I tried to follow all the instructions I found on this forum and elsewhere, on a very long search for help. None of them directly addressed my problem.
They all gave answers for creating multiple files with meaningless names. I don't see the utility in creating a bunch of files named 1.txt, etc, or a.txt, or some combination with a leading standard meaningless lead like filename, or sample...
I may be wrong about that lack of usefulness, but at the very least, it's not what I tried to ask and get an answer for.
I already have the meaningful filenames I want, a lot of them. I want to create many empty text files with names that I already have.
The only remotely useful suggestion (for me) that I got was using touch from a linux or bash prompt.
I found that if I wrapped my titles in quotations and separated the titles by a single space I could get the touch command to kind of work. I also discovered that my file titles could not contain any forward slashes ("/"). Nobody explained to me that the titles had to be wrapped in quotes. I figured that out quickly. Nobody told me how to separate the filenames. I experimented until I found a separation that worked.
I tried some experimenting with the {} bracing and the touch command but wound up not being able to figure out how that could help me in my particular case.
Also, I don't know if it has to do with a buffer on the bash or in PowerShell (I tried using both the Git installation in Windows 10 and bash from PowerShell 7.2.1, but I found that only about seven titles in the list would be touched. The rest resulted in a command not found error.
I broke up the list into about seven titles each and ran touch on each of those filenames (my titles) list segments. That way, on that very list sample I display above from my lectures.txt file, I got my empty text files created successfully, even though I had to do it in three touch commands.
I may have confused some of the people who tried to help me by putting all the titles in a text file that I named lectures.txt.
The contents of that file were the titles I wanted for my text files. Thank you so much those who did reach out to me.
I had already found something that might work in bash but I couldn't get it to work. It was roughly on the line of
`touch prefix{1..3}.txt`
This had the same problem that all the other command suggestions I found had as well, like
echo > filename.extension
The same for the apparently most popular
for /l %a in (1 1 10) do type nul > "%a.txt"
which created ten files named 1.txt through 10.txt. That was not the least bit useful to me.
I know my question got voted down as being exceptionally bad, but I'm editing and adding what I found out, so maybe sort of answering my own question.
If you are looking to do what I'm trying to do, and not just create meaningless filenames, I hope you will find some of what I did helpful. Here's a list of suggested solutions of which NONE did I find useful.
https://techpp.com/2021/08/22/create-file-using...
https://www.quora.com/Can-you-create-multiple-f...
https://www.howtogeek.com/725207/how-to-create-...
How to create multiple empty files on cmd(Windows).
Create multiple files with Powershell?.
https://www.laptopmag.com/how-to/create-multipl...
Remember that using space in bash is not recommended, but if you need to...
You can try something like that:
counter=1
for title in $(cat lectures.txt)
do
touch "$counter - $title.txt"
counter=$((counter+1))
done
EDIT
I only added the title on lectures.txt
NEW EDIT
If lectures.txt has 1 title per line you can do this:
while IFS= read -r line || [ -n "$line" ]
do
touch "$line"
done < lectures.txt
Get-Content -Path '.\lectures.txt' | ForEach-Object { New-Item -Path ".\$($_)" }
or using aliases it's: gc '.\titles.txt' | % { ni ".\$($_)" }
from a powershell console at the required folder and enter the command.

Possible to copy/move/etc multiple files of same base name via Windows CMD/.BAT?

I am wondering if it is possible to accomplish the following, given some context and example.
I have files in "Server\Share\Folder\File##.ext"
Sometimes the "File##.ext" can be "File01.ext" through "File20.ext", and other times it may be "File01.ext" through "File40.ext"
Sometimes there are less of these files, sometimes there are more.
I want a batch file to take the files from "Server\Share\Folder\File##.ext" and move them to "Server\Share\OtherFolder\File##.ext". I know I can accomplish this easily with:
copy /y "Server\Share\Folder\File01.ext" "Server\Share\OtherFolder\File01.ext"
Then just add another line for each extra "File02.ext, File03.ext, etc., but I am wondering if it is possible to make it so that any file that resembles "File##.ext" can be included, so that no matter how many ## I have, it always works without issue.
Thanks in advance for any and all advice!
EDIT
Someone mentioned using Wildcards, but my question with that is - lets say those files are File01.ext through File05.ext, will it match what it finds to the newly moved file? Like will it find File01 from File?? on the source and Make it File01 from File?? at the destination?
You can accomplish this task with a FORloop program in batch-file.
You can also loop through the Commands using : and variable name.
Combining these two would help you get what you want.
We can help you with Ideas and little bit of the coding. But the Efforts must be done by you. So U can learn programming better

Xcopy creates blank/empty csv files

I have a batch file that I use (and have used all day successfully) to copy some badly named files (all are 1.csv) in a horrendously long dir tree to a different location with a more appropriate name (and shorter route to the file). It suddenly quit working; specifically, it IS making the new directory and it IS making the file with the correct name; however, the 'new' file is basically void. The source file may be 26mb but the destination file created is 287k. I'm using
xcopy "Z:\jobs\!q-z\clientname\tars\2016_06_06\home\abcd\xyz\qwert\more\moarr\deeper\deepest\x\y\z\1.csv" "Z:\jobs\!q-z\clientname\daily\160606\biz.csv*"
As I said earlier, this was working just fine all day long and suddenly began creating all dest files exactly the same size, which is an empty shell of a csv file. I have a feeling this might have to do with some sort of "cache" issue, but if so, I don't know how to clear it. Or is there some error in my syntax that allowed it to work almost accidentally before today? I've tried using pretty much every switch for xcopy, with no better results.
Also, the only thing that ever changes in the batch file is the date.

Command Prompt: Move a file to an Unknownly named folder

So, is there a possible way to move Test.txt to C:\ProgramData\CsD2\Tools\("Unknown Folder Name")\data\per Using command prompt?
using foxidrives solution for your previous question for detecting the correct directory, then just
move test.txt "%folder%\"
Short answer: yes. Not quite sure what the situation is that has left only the middle part of your path unknown, and the need to use the comnand line, but I have encountered similar cases on Linux and expect the algoirthm can be adapted to Windows commands. It's possible to do this by hand rather than writing a shell script, but it's up to you and your skills.
Permissions matter. Make sure you elevate yours enough to read and write in Tools before continuing.
First, change directory to C:\ProgramData\CsD2\Tools\
Presumably there are many items here. Some may be "hidden," so list the contents of this directory and be sure to include an option to show hidden files and folders. If you can, restrict the search to directories only.
It's tempting to display contents recursively in the above step. It's up to you, but I find it makes the output cluttered without a script to do the rest of the work.
Now it's time to search for the subfolder set that theoretically only exists in your target folder. Suppose Tools contains the directories fldr1, fldr2, and fldr3. Use your command to list a directory's contents with the path "fldr1\data\per", then use "fldr2\data\per", and so on until it doesn't return an error. Per may be empty, but that should look different from the path not found error.
Now you've found the name of your mystery folder. Write it down for future reference.
At thus point, you know the path to Test.txt, and the full path to the destination directory. Do a move command to relocate Test.txt, and you're done. I like to relist the contents of the target directory after to be comfortable that it arrived.

Rename file in Win32 to name with only differences in capitalization

Does anyone know a pure Win32 solution for renaming a file and only changing its capitalization, that does not involve intermediate renaming to a different name or special privileges (e.g. backup, restore).
Since the Win32 subsystem generally regards two file names differing only in capitalization as the same, I haven't been able to find any solution to the problem.
A test program I made with the MoveFile API seems to work. So does the rename command in cmd.exe. What have you tried, and what error are you getting?
This isn't relevant, but further testing shows that renaming a long filename in this way works but will change the short filename (alternating between ~1 and ~2 for example), incidentally.
Just use the normal MoveFile API. That call probably just turns into ZwSetInformationFile(..., FileRenameInformation,...) The docs for FILE_RENAME_INFORMATION states that you need DELETE access and the file can't be locked etc, but those restrictions will probably apply to other solutions also.
I do not believe there is a way to expose two files with identical names that differ only in spelling to the Win32 subsystem. Even if some how you were able to create these files, the most likely result would be that only one file would be accessible - defeating the purpose of staying soley in Win32.
If you want to go into the Native layer, you can create a file with NtCreateFile and InitializeObjectAttributes w/o OBJ_CASE_INSENSITIVE or you can pad the end with extra spaces (if you pad with extra spaces, the file will not be accessible from Win32 dos paths). See here: http://www.osronline.com/ddkx/kmarch/k109_66uq.htm . I'm pretty sure you were already aware but I included it incase you did not know.
So long as your file is not immediately needed by another program, you can use my solution.
When you rename the file, capitalize, and delete the last letter. Then rename again and return the letter.
:)

Resources