top of page
jimtingpissadite

Robocopy Folders With Ampersands In The Name



So I have a pretty basic batch script that looks at an incoming folder and based on file type moves files where I want them. Now folders that show up with "&" in them break it. How do you go about fixing this? I couldn't find an obvious answer online.


Besides the invalid characters that OneDrive can correct for you, other characters and combinations of characters may also prevent files and folders from syncing. These other characters have special meanings when used in file names in OneDrive, SharePoint, Windows and macOS, such as "*" for wildcards, "\" in file name paths, and names containing .lock, CON, or _vti_.




Robocopy folders with ampersands in the name



If you're syncing files and folders with OneDrive for work or school, Microsoft has a support tool that can rename additional unsupported file and folder names. Read more about the Support and Recovery Assistant. This tool will only rename files and folders that you store in OneDrive for work or school (when you're signed in with your work or school account). It doesn't rename files or folders on your OneDrive.com when you're signed in with your Microsoft account.


I have been looking for a solution to this problem for a while now. I work on old closed systems that can't have new packages installed. I don't have the rename command. Finally I wrote a script that appears to work with all keyboard entered special characters. @#$%^&*()-_=+[]\;:",?' The script will rename every file and directory in the current directory. It will replace all special characters,except -_. with the _ character. The outfile= line can be modified to use a different character for replacement if desired. Replace _ with . to use the . character for example.


%%Many characters such as \ = ( ) do not need to be escaped when they are used within a "quoted string" typically these are characters you might find in a filename/path. The percent character is one exception to this rule, even though under NTFS % is a valid filename character.


The $using construct is another popular way to pass local variables to a remote scriptblock. This construct allows you to reuse the existing local variables but simply prefacing the variable name with $using:. No need to worry about an $args collection nor adding a parameter block.


Keep in mind that you will need to end the destination folder name with a \, otherwise, you will rename the file. This is also one of the useful features of the Copy-Item cmdlet, we can specify a new name for the file on the destination:


IMHO, the optimal tools for dealing with hordes of files are find and xargs. See man find. See man xargs. find, with its -print0 switch, produces a NUL-separated list of filenames (filenames may contain any character execpt NUL or /) that xargs understands, using the -0 switch. xargs then builds the longest command allowed (the most filenames, no half-filename at the end) and executes it. xargs repeats this until find supplies no more filenames. Run xargs --show-limits


nohup creates a log file called 'nohup.out' with the command output. The basic "mv" command doesn't create any output, but "cp" outputs the name of each file it copies. If you use "cp" to copy a LOT of small files (300,000+), you risk having nohup.out get quite large - large enough to fill up your unRAID server ramdisk - not a good thing.


Both commands start the Windows command interpreter, issuing a dir command on the Program Files folder. Because this foldername contains a space, the value needs surrounded with escaped quotes. Note that the first command specifies a string as ArgumentList. The second command is a string array.


If you install Clink from the .zip file then enhanced default settings are activated when the default_settings and default_inputrc files are present in the binaries directory or in the profile directory. The .zip file comes with the files, but their names have a _ prefix so that enhanced defaults won't automatically take effect. You can activate the enhanced default settings by renaming the files to remove the _ prefix.


Names can be used to refer to simple keys like Space, Return, Tab, letters and digits (A, b, 1, ...), and most punctuation (!, @, ., _, ...). Names can also include modifier prefixes C- or Control- for the Ctrl key, or M- or Meta- for the Meta or Alt key. However, modifier prefixes don't work with simple key names; you can't use C-Space, instead a sequence is needed for special keys like that.


The $if term= form may be used to include terminal-specific key bindings, perhaps to bind the key sequences output by the terminal's function keys. The word on the right side of the "=" is tested against both the full name of the terminal and the portion of the terminal name before the first "-". This allows sun to match both sun and sun-cmd, for instance. This is not useful with Clink, because Clink has its own terminal driver.


If a script defines more than an argmatcher, then putting it in a completions directory may cause its other functionality to not work until a command is typed with the same name as the script. For example, if a script in a completions directory defines an argmatcher and also a prompt filter, the prompt filter won't be loaded until the corresponding command name is typed. Whether that is desirable depends on the script and on your preference.


Clink expands CMD prompt $ codes in %CLINK_RPROMPT%, with a few exceptions: $+ is not supported, $_ ends the prompt string (it can't be more than one line), and $V is not supported. Additionally, if %CLINK_RPROMPT% ends with $M then trailing spaces are trimmed from the expanded string, to maintain right alignment since $M includes a space if the current drive is a network drive (so e.g. $t $d $m is right-aligned regardless whether the current drive has a remote name).


You can bind a key to a Lua function by binding it to a macro that begins with "luafunc:". Clink will invoke the named Lua function when the key binding is input. Function names can include periods (such as foo.bar) but cannot include any other punctuation.


The pathname is the full path to the cURL application along with all of its parameters. The window style basically tells it how to display the terminal window. We prefer setting the style to 1 since it leaves the window open while it runs and makes it easier to see if the job is running, has an issue or has completed.


We use cURL to get the token. Once the token is received then we can go directly to PJM. No username or password is required. To interface with PJM directly without cURL you can use the following Visual Basic adapted from the example provided by PJM.


To create a valid list of report short names use the get report list weblink. Then remove all spaces, make the list all lowercase and then search for "&" and replace with "%26" (ignoring the quotes). The report:


ISO-NE directs you to use their web services for public data. To use you will need to sign up for ISO Express and select the ISO Data Feeds box during registration. They provide a list of all endpoints on their documentation page. To query you will need to use basic authentication with your ISO Express username and password. Typically your username is your email address.


Last week, i began switching all of my scripting over from a combination of xcopy + xxcopy over to robocopy since our MS licensing allows us to use it at no cost, has built-in switches for easily logging the copy process, PLUS it had the copy status % and ETA options. Once I got to one of the last scripts, I figured out that robocopy cannot search multiple files on disk and place them into a single folder (aka concatenate). An example is to search for all .PST files and place them into a single folder such as "%userprofile%\my documents\archives". XXCopy has this feature (use the /SG switch) and it works very well. Plus, if a duplicate name is encountered during the copying process, it simply takes (file #1 - archive.pst) and makes it archive0001.pst. Otherwise, all filenames are exactly what they were before.


The amperand (&) symbol means something special in DOS command line lingo, and is uncommon in file/folder names, so it's not tremendously surprising some tools might have a problem with it. They're not handling it properly.


Aside from that strange recursion problem with "Application Data", I have other pathnames that exceed 255 chars. I'd like to be able to copy those. In any case, attempts to filter those didn't work either. Looks like it's back to the drawing board with Synctoy, Robocopy, Xcopy, etc. I saw a few references to XXcopy in this thread; I think I'll take a look at that.


No, I have not experienced any file corruption issues (at least that I can tell). I've used RichCopy recently with the settings I described to migrate a large department's data from an old Novell server to Windows. The migrated folders are pretty heavily used by several hundred users, and I have not had any reports of corrupted files.


does anyone know if you can consolidate folders? For example, I have a SD card from my camera. I put it in the card reader. I have a script that will first ask for the name of the new folder you would like the script to create, then, it will take pictures from multiple folders on the card and dump them into that newly created folder without the card's folder structure. It just places all pics into the root of that new folder, regardless of where they came from.


Sorry, but I don't see the value of this program. I just wanted to be able to copy a folder tree and have it keep the original date stamps on the folders. I was told this was just Robocopy with a GUI interface. I don't see that at all. 2ff7e9595c


0 views0 comments

Recent Posts

See All

Comments


bottom of page