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

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

Related

Need help understanding a move script written for CMD involving multiple subdirectories into one directory

I got a folder with a lot of images in it, and I'd like to move everything to the main folder so basically I would like to turn this:
L:\Pixiv\Tags\44324\Image1.jpg
L:\Pixiv\Tags\4564356\Image2.jpg
L:\Pixiv\Tags\325423\Image3.jpg
L:\Pixiv\Tags\16324\Image4.jpg
...into this
L:\Pixiv\Tags\Image1.jpg
L:\Pixiv\Tags\Image2.jpg
L:\Pixiv\Tags\Image3.jpg
L:\Pixiv\Tags\Image4.jpg
I did some looking, and I discovered a move function for CMD, and while most of it I can understand, some of it I can't, and frankly, I'm just that smart enough to know what happens when you start playing around with stuff you don't fully understand, so I don't do it. Point is your basic move function is basically something like "move c:\Whatever C:\Whocares," but as you can tell from below, this is a little more complicated.
for /r %d in (*) do move "%d" "d:\all snaps\"
/r I think goes through all the folders at the current target directory. So if I'm in L:\Pixiv\Artists and I type in this code for L:\Pixiv\Artists as a destination folder every file in Artists is going to be dumped into Tags. Is this correct?
%d I couldn't make sense out of, so I've no idea what it does. Also, for ease of use, I would like to put this in a batch script, because boy howdy, do I got a lot of folders that needs to be fixed. From what little I was able to read I should write the same as above, but change %d to %dd, correct? Also where at would I add a target directory, so I could just write a batch script, and be done with it? Also, apologies in advance for my lack of knowledge, usually I use Batchrun when it comes to automating stuff.

How can I edit the columns of multiple files in the same folder then overwriting it?

I am at the edge of frustration thats why my way of explain myself might be rough.
I am trying to remove a column from a tab delimited text files. I have 10 files with same pattern of names such as (written below), thats why when I use such commands like cut I get frustrated with using tab many times.
So my questions;
1) Is there a easier method of basically copying the file name for overwriting?
cut -f 1,3 oldfile.txt > oldfile.txt
btw when I do the method above, my all lines got erased for some reason.
2) Since I dont know the regular expression well enough, is there a way to go around of awk ? that language seems pretty complicated for me.
3)What is the most memory efficient method for his task? Please tell me a method then I will learn that method even its as hard as learning Chinese.
I am a unix frasturared mediocare. sorry for my bad england.
Best regards,
file name example: KKK12398801_normal_912839.txt

How to split a large csv file into multiple files in GO lang?

I am a novice Go lang programmer,trying to learn Go lang features.I wanted to split a large csv file into multiple files in GO lang, each file containing the header.How do i do this? I have searched everywhere but couldnt get the right solution.Any help in this regard will be greatly appreciated.
Also please suggest me a good book for reference.
Thanking You
Depending on your shell fu this problem might be better suited for common shell utilities but you specifically mentioned go.
Let's think through the problem.
How big is this csv file? Are we talking 100 lines or is it 5G ?
If it's smallish I typically use this:
http://golang.org/pkg/io/ioutil/#ReadFile
However, this package also exists:
http://golang.org/pkg/encoding/csv/
Regardless - let's return to the abstraction of the problem. You have a header (which is the first line) and then the rest of the document.
So what we probably want to do (if ignoring csv for the moment) is to read in our file.
Then we want to split the file body by all the newlines in it.
You can use this to do so:
http://golang.org/pkg/strings/#Split
You didn't mention but do you know how many files you want to split by or would you rather split by the line count or byte count? What's the actual limitation here?
Generally it's not going to be file count but if we pretend it is we simply want to divide our line count by our expected file count to give lines/file.
Now we can take slices of the appropriate size and write the file back out via:
http://golang.org/pkg/io/ioutil/#WriteFile
A trick I use sometime to help think me threw these things is to write down our mission statement.
"I want to split a large csv file into multiple files in go"
Then I start breaking that up into pieces but take the divide/conquer approach - don't try to solve the entire problem in one go - just break it up to where you can think about it.
Also - make gratiutious use of pseudo-code until you can comfortably write the real code itself. Sometimes it helps to just write a short comment inline with how you think the code should flow and then get it down to the smallest portion that you can code and work from there.
By the way - many of the golang.org packages have example links where you can literally run in your browser the example code and cut/paste that to your own local environment.
Also, I know I'll catch some haters with this - but as for books - imo - you are going to learn a lot faster just by trying to get things working rather than reading. Action trumps passivity always. Don't be afraid to fail.
Here is a package that might help. You can set a necessary chunk size in bytes and a file will be split on an appropriate amount of chunks.

Creating a Continuous File Reading-Executing Shell Script

I need to write something that will read and execute all the files(Mainly executable scripts) inside one or more folders; in other words, a continuous chain with a break when finished. I'm new to shell and need syntax help. I'm on Ubuntu 12.10-Gnome btw.
Here are some main highlights I think should be included;
-The program should ask for one or more directories. Should process all the files given in these directories,
-Should create a .txt file on which files and folders are read and executed(for correction and informational purposes),
-Could contain a break option like control+shift+c maybe but thats clearly not of utmost importance.
The code, or the guidance to the code would be very much appreciated. Thx alot.

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