VB Script; Identifying file paths of more than 255 characters - windows-7

I am currently trying to write a VB script in order to identify file paths that are too large (255+), in a large hierarchical network structure. These are usually truncated and end with a tilde (~). I need to get the file paths outputted onto a text file, so that someone can manually decide what to do with them. Scanning the whole server would be too large a job, and so I was hoping to be able to run the script on certain folders and their sub-folders.
I am quite comfortable with VB for access, but have never used VB Script to manipulate directories like this.
I'm using windows 7, and the directories could be server based.
Any help would be greatly appreciated. Thanks :)

If your problematic paths ends with a ~, you can use
dir /s /b x:\someFolder1 | findstr /e /c:"~" > paths.txt
dir /s /b x:\someFolder2 | findstr /e /c:"~" >> paths.txt
....

Related

dir command output different results between local dirves and network drives [duplicate]

This question already has an answer here:
Why are also *.tiff files output by Windows command DIR on searching for *.tif files?
(1 answer)
Closed 2 years ago.
I just test a piece of cmd on my computer:
C:\Users\user>dir D:\test\*.xls /b
test - copy.xls
test - copy.xlsx
test.xls
test.xlsx
C:\Users\user>dir Y:\test\*.xls /b
test - copy.xls
test.xls
The two test file fold is absolutely the same. Dirve "D" is a local dirve and dirve "Y" is a network dirve. I checked the version of my machine and the source machine of dirve "Y", they were different indeed. Here are my questions:
I only plan to run my program on local machine, is there an option to always output the second results?
If it is "No" to question 1, may I add some option like -*.xlsx to remove *.xlsx results from my program?
Thanks in advance.
I can exclude *.xlsx like this:
dir D:\test\*.xls /b | findstr /v /i "\.xlsx$"
Will exclude even xls.* too:
dir D:\test\*.xls /b | findstr /v /i "\.xls.$"
Obviously on your local computer short 8dot3 file names are enabled.
You can see that when running dir /x ...
There are different ways to generate 8dot3 file names. Usually an extension with more than three letters is truncated, e.g
.xlxs leads to .XLS
The dir command always searches in both long filenames and 8dot3 file names.
You have some options to change that behaviour:
Disable 8dot3 file names. This may be done with fsutil.exe, either per drive or for the complete system.
Change the way how 8dot3 file names are generated in the registry.
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"Win95TruncatedExtensions"=dword:00000000
In this case .xlsx would lead to .XL~
Note:
When you do any of these changes, it works first for newly created files.
For older files you should copy them.
But when you want to disable all 8dot3 file names you can use fsutil.exe to strip 8dot3 file names in older files.

How to view duplicate files in a drive using command in cmd

I want to view all the duplicate files present in a
drive using command prompt. I have tried a few commands like tree but I am not satisfied by it.
I'll assume you are simply looking for duplicate file names, regardless of content.
This is inherently a relatively slow process. If you want a script based solution, then your best bet is probably to write a custom powershell, VBScript, or JScript script.
But I have a pair of pure script based utilities that can give decent performance. You should still expect the command to take many minutes to begin printing results (perhaps hours? if a large drive). The entire directory listing must fit within 2 GBytes. This command will fail if the limit is exceeded.
This will not allow you to see files for which you do not have access.
jren "^.*" "name()+' : '+path()" /list /j /s /p c:\ | sort | jrepl "^(.*? : ).*\n(?:\1.*\n)+" "$0" /m /i /jmatch
The above works by first using JREN to recursively list all files, one file per line as
fileName : fullFilePath
The list is then sorted, and then JREPL is used to extract consecutive lines where the leading file name repeats.
JREN.BAT is available at http://www.dostips.com/forum/viewtopic.php?f=3&t=6081
JREPL.BAT is available at http://www.dostips.com/forum/viewtopic.php?f=3&t=6044
Use JREN /? and JREPL /? to get full documentation on the utilities.

VB script to list folders and contents

I would like to write a VB script that will:
List all folders named "abc", and also there contents, in share drive \share1
Currently these folders named "abc" are located all over the place in \share1, but they all have the same name.
The issue I have is that some of these paths are long paths, hence getting this working through PowerShell has been very difficult, as it keeps hitting the 260 limit.
Prefixing a path with \\?\ allows paths up to 32,000 odd characters. This allows apps to opt in to very long file names as they crash most programs. Now it depends on how you access the file functions if the component will allow you. CMD does support this.
so a command line
for /f %A in ('dir c:\windows\abc /s /b /ad') do dir "\\?\%A"
\\?\ works with unc paths too.
for /f %A in ('dir \\?\c:\windows\abc /s /b /ad') do dir "%A"
I think that RoboCopy (the Windows utility) is your best bet. This can handle long path names, and it can actually be used to just list files, rather than copy them, by using the
/L option (: List only - don’t copy, timestamp or delete any files.)
http://ss64.com/nt/robocopy.html provides a good summary of all the options.
You can also download a GUI for it which might make it a bit easier to work with.
Another option is to shorten the path via subst:
subst X: C:\very\...\long\...\path

Windows CMD search

Description:
Since my previous post of using a .bat file to search for file names (Find multiple files from the command line),
I have figured out how to run a .bat file to search a server for specific file names. Now, I want to do the same thing but I want to include in my search the entire contents of a directory.
All of this will be done in windows command prompt and of course a notepad file if needed. I do not have access to linux or unix so please no responses that include such.
Example -
I Drive
+Drawings
++Structural
So for the example above I want to take the entire contents of dir structural (which may be 1000s of .dwg) and using a .bat file search a server with it.
Also I put these commands in notepad and renamed it from a .txt to a .bat
My single file search
dir [file.dwg] /s/4
Entire Directory Search (which does not work this is what I am trying to do)
dir [original dir] /s/4
After i finished writing my .bat file in notepad I would simply put it in the server directory location that I needed to search and run it.
I hope I have made myself clear and I hope that you can help because Im not sure what to do here.
See(Folder Comparisons Via Command Line) for what I am trying to do only I need to compare the directory and all sub directories.
In an effort to understand what you want, here is an example batch file:
DIR G:\Structural /S /B
G:\Structural\cad2012.dwg
G:\Structural\cad2013.dwg
G:\Structural\cad2014.dwg
G:\Structural\photo2012.jpg
If you just want to find the files with 2012
DIR G:\Structural /S /B | FINDSTR 2012
G:\Structural\cad2012.dwg
G:\Structural\photo2012.jpg
If you just want to find the dwg files from 2012
DIR G:\Structural /S /B | FINDSTR 2012 | FINDSTR /R /I dwg$
G:\Structural\cad2012.dwg
Have a look at what I wrote in response to the question "batch file - Compare in windows command prompt" which I think is getting close to what you want to do.

Win 7: CMD batch file for creating directories based on filenames

I'm working on a CMD line batch file in a Win7 environment that will create directories based upon the filenames listed in a directory.
I am using this code, but the output created is partial and incomplete with only
setlocal enabledelayedexpansion
for /r %%i in (*.wav) do (
set filename1=%%i
set folder1=!filename1:~4,10!
mkdir !folder1!
)
pause
I have this script saved as a CMD file in text format in the source directory, on a local harddrive, though it is in a subdirectory.
The directory output is partial and broken, with garbled output and the numbers of directories created does not match the number of files, and the created directories seem to nest. I've researched this and can't seem to find a definitive answer.
It's not entirely clear what it is you are trying to accomplish. Are you trying to create a directory within the same directory containing the wav file, just without the .wav extension? If so, you're missing some quotation marks and you're stripping the wrong end of the filename off. If that's what you are trying to accomplish, it can actually be done with a single command, no batch script needed. Type this at the command prompt:
for /r %I in (*.wav) do mkdir "%~pnI"
Of course, if you still want it in a batch script, use %%I and %%~pnI with double percents instead of single. See the last couple of pages of help for for an explanation of how %%~pnI works.

Resources