New files may be on different file systems or drives new directories must be on the same drive. REN lets you change the name of a file or a subdirectory, or move one or more files to a new subdirectory on the same drive. If you don't specify any arguments, REN will display its command dialog. Internet: Can be used with FTP/HTTP Servers and HTTP/HTTPS servers. Use wildcards with caution on LFN volumes see LFN File Searches for details. The result: Every file that matches the search criteria (*.gif) will have the sdrename.vbs script executed against it.Supports command dialog, attribute switches, extended wildcards, ranges, multiple file names, delayed variable expansion, and include lists. Then, run the following from a command prompt: renloop *.gif For example, if I wanted to copy and rename all files within c:\mydocs\images\, both files would be copied into this directory. To use, copy both script files to the starting directory – the top directory you want to include in the rename. for /r %%i in (%1) do cscript.exe sdrename.vbs "%%i" This calls the shell’s for command to loop through all subdirectories, retrieving the full file name and path for each file that matches the search criteria. The second script is a simple one-line batch file, which I call renloop.bat (as in rename loop). Option Explicit 'Filenames are required If = 0 Then WScript.Echo "> Must provide file name!!! <<<" WScript.Quit End If Dim strFile, strRootFolder, strFilename, strNewFilename, objFSO WScript.Echo "*** SUBDIRECTORY FILE RENAMING ***" WScript.Echo "" strFile = WScript.Arguments(0) WScript.Echo "Processing: " & strFile strRootFolder = Left( WScript.ScriptFullName, InStr( WScript.ScriptFullName, WScript.ScriptName ) - 1) WScript.Echo "Root Folder: " & strRootFolder strFilename = Mid( strFile, InStrRev( strFile, "\" ) + 1 ) WScript.Echo "Filename: " & strFilename strNewFilename = Mid( strFile, Len( strRootFolder ) + 1 ) WScript.Echo "Subfolders: " & strNewFilename strNewFilename = Replace( strNewFilename, "\", "" ) WScript.Echo "New Filename: " & strNewFilename Set objFSO = CreateObject( "Scripting.FileSystemObject" ) objFSO.CopyFile strFile, strFilename WScript.Echo "File copied successfully." objFSO.MoveFile strFilename, strNewFilename WScript.Echo "File renamed successfully!" WScript.Echo "*** PROCESS COMPLETE ***" Rename the copied file to the new filename (step 6).Determine the new filename (step 4 + step 3).Strip backslashes out of the subfolders extract (step 4).Extract the names of all subfolders between the root folder and the file.Extract the filename (only) from the full path of the file.Determine the root folder (the folder that the script file is executed in).Retrieve the full, absolute path to the file from command line arguments.I name this file sdrename.vbs (as in subdirectory rename). The first script file is a Windows Script Host file, written in VBScript. Second, I needed a script file which would find every file under a given subdirectory and call the first script file for each file found. First, I needed a script file that would make a copy of a file and rename it by prepending the names of its parent folders to the filename. Essentially they want a file whose path is \A\01\23\45.tif to be renamed to A012345.tif. She has image files stored in a directory structure, and she wanted to be able to pull the files out and rename them with the parent directories. A coworker had an odd little requirement that they asked me if I could help with.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |